diff --git a/2015-2016/G/07/02/task1.c b/2015-2016/G/07/02/task1.c new file mode 100644 index 00000000..65163fc0 --- /dev/null +++ b/2015-2016/G/07/02/task1.c @@ -0,0 +1,38 @@ +#include + +void minmax(int *, int, int *, int *); + +int main() +{ + int arr[500], size, min, max, counter; + int sum; + + scanf("%d", &size); + if(size > 0 && size < 500){ + for(counter = 0; counter < size; counter++){ + scanf("%d", &arr[counter]); + } + } + + minmax (arr, size, &min, &max); + + sum = max + min; + + printf("%d\n", sum); + + return 0; +} + +void minmax(int *arr, int size, int *min, int *max) +{ + int i; + + for(i = 0; i < size; i++){ + if(arr[i] > *max){ + *max = arr[i]; + } + if(arr[i] < *min){ + *min = arr[i]; + } + } +} \ No newline at end of file diff --git a/2015-2016/G/07/02/task2.c b/2015-2016/G/07/02/task2.c new file mode 100644 index 00000000..ab65a1fa --- /dev/null +++ b/2015-2016/G/07/02/task2.c @@ -0,0 +1,37 @@ +#include +#include + +char* find(char *, char); + +int main() +{ + char haystack[400], needle; + char *i = 0; + + scanf("%[^\n]s",haystack); + getchar(); + scanf("%c",&needle); + + if(find(haystack ,needle) == NULL){ + printf("-1\n"); + } + else{ + i = find(haystack ,needle); + printf("%d\n",(int)(i - haystack)); + } + + return 0; +} + +char* find(char *haystack, char needle) +{ + int counter = 0; + + while(haystack[counter] != '\0'){ + if(haystack[counter] == needle){ + return &haystack[counter]; + } + counter ++; + } + return NULL; +} diff --git a/2015-2016/G/07/Homework-08/task2.c b/2015-2016/G/07/Homework-08/task2.c new file mode 100644 index 00000000..04c331fd --- /dev/null +++ b/2015-2016/G/07/Homework-08/task2.c @@ -0,0 +1,33 @@ +#include +#include +#include + + +int main() +{ + int i; + int sum = 0; + char msg[200]; + int box ; + scanf("%[^\n]s", msg); + box = strlen(msg); + for (i = 0; i < box; i++) + { + if(msg[i] == 'a'||msg[i] == 'd'||msg[i] == 'g'||msg[i] == 'j'||msg[i] == 'm'||msg[i] == 'p'||msg[i] == 't'||msg[i] == 'w'||msg[i] == ' '){ + sum = sum + 1; + } + if(msg[i] == 'b'||msg[i] == 'e'||msg[i] == 'h'||msg[i] == 'k'||msg[i] == 'n'||msg[i] == 'q'||msg[i] == 'u'||msg[i] == 'x'){ + sum = sum + 2; + } + if(msg[i] == 'c'||msg[i] == 'f'||msg[i] == 'i'||msg[i] == 'l'||msg[i] == 'o'||msg[i] == 'r'||msg[i] == 'v'||msg[i] == 'y'){ + sum = sum + 3; + } + if (msg[i] == 'z'||msg[i] == 's') + { + sum = sum + 4; + } + } + + printf("%d", sum); + return 0; +} \ No newline at end of file diff --git a/2015-2016/G/07/Homework-08/task3.c b/2015-2016/G/07/Homework-08/task3.c new file mode 100644 index 00000000..65b5086c --- /dev/null +++ b/2015-2016/G/07/Homework-08/task3.c @@ -0,0 +1,38 @@ +#include + +int main() +{ + int raindeers, i, a, j; + int num[200]; + + printf("Incert the number of the raindeers.\n"); + scanf("%d",&raindeers); + while(raindeers % 2 == 0){ + printf("Incert correct number of raindeers.\n"); + scanf("%d",&raindeers); + } + for (i = 0; i < raindeers; ++i) + { + scanf("%d",&num[i]); + } + + for (i = 0; i < raindeers; ++i) + { + for (j = 0; j < raindeers; ++j) + { + if(num[i] == num[j]){ + a = 1; + } + else{ + a = 0; + } + } + if(a == 0){ + printf("%d\n", num[i]); + break; + } + } + + return 0; +} + diff --git a/2015-2016/G/07/Homework-09/task1.c b/2015-2016/G/07/Homework-09/task1.c new file mode 100644 index 00000000..fcd024b7 --- /dev/null +++ b/2015-2016/G/07/Homework-09/task1.c @@ -0,0 +1,34 @@ +#include + +int main() +{ + int a, b, i, helper[32]; + scanf("%d", &a); + scanf("%d", &b); + + for(i = 1; i > 0;){ + if(a < 0 || a > 7) + { + printf("enter a valid a\n"); + scanf("%d", &a); + } + } + for(i = 1; i > 0;){ + if(b < 0 || b > 200) + { + printf("enter a valid b\n"); + scanf("%d", &b); + } + } + + for(i = 32; i != 0 ; i--) + { + helper[i] = b % 2; + b /= 2; + } + + printf("%d\n", helper[a]); + + return 0; +} + diff --git a/2015-2016/G/07/Homework-09/task2.c b/2015-2016/G/07/Homework-09/task2.c new file mode 100644 index 00000000..22674f47 --- /dev/null +++ b/2015-2016/G/07/Homework-09/task2.c @@ -0,0 +1,44 @@ +#include + +int main() +{ + int n, v, p, i, help[32], sum, j, a; + scanf("%d", &n); + scanf("%d", &v); + for(i = 1; i > 0;){ + if(v != 0 && v != 1) + { + printf("enter a valid V\n"); + scanf("%d", &v); + } + } + scanf("%d", &p); + for(i = 1; i > 0;){ + if(p < 0 || p > 7) + { + printf("enter a valid P\n"); + scanf("%d", &p); + } + } + for(i = 32; i != 0 ; i--) + { + help[i] = n % 2; + n /= 2; + } + help[p] = v; + sum = 0; + j = 32; + for (i = 32; i < 0; --i) + { + a = 1; + while(j > i) + { + a = 2 * a; + j--; + } + sum = a * help[i] + sum; + } + printf("%d\n", sum); + + return 0; +} \ No newline at end of file diff --git a/2015-2016/G/07/big_homework/task2.c b/2015-2016/G/07/big_homework/task2.c new file mode 100644 index 00000000..04c331fd --- /dev/null +++ b/2015-2016/G/07/big_homework/task2.c @@ -0,0 +1,33 @@ +#include +#include +#include + + +int main() +{ + int i; + int sum = 0; + char msg[200]; + int box ; + scanf("%[^\n]s", msg); + box = strlen(msg); + for (i = 0; i < box; i++) + { + if(msg[i] == 'a'||msg[i] == 'd'||msg[i] == 'g'||msg[i] == 'j'||msg[i] == 'm'||msg[i] == 'p'||msg[i] == 't'||msg[i] == 'w'||msg[i] == ' '){ + sum = sum + 1; + } + if(msg[i] == 'b'||msg[i] == 'e'||msg[i] == 'h'||msg[i] == 'k'||msg[i] == 'n'||msg[i] == 'q'||msg[i] == 'u'||msg[i] == 'x'){ + sum = sum + 2; + } + if(msg[i] == 'c'||msg[i] == 'f'||msg[i] == 'i'||msg[i] == 'l'||msg[i] == 'o'||msg[i] == 'r'||msg[i] == 'v'||msg[i] == 'y'){ + sum = sum + 3; + } + if (msg[i] == 'z'||msg[i] == 's') + { + sum = sum + 4; + } + } + + printf("%d", sum); + return 0; +} \ No newline at end of file diff --git a/2015-2016/G/07/big_homework/task3.c b/2015-2016/G/07/big_homework/task3.c new file mode 100644 index 00000000..65b5086c --- /dev/null +++ b/2015-2016/G/07/big_homework/task3.c @@ -0,0 +1,38 @@ +#include + +int main() +{ + int raindeers, i, a, j; + int num[200]; + + printf("Incert the number of the raindeers.\n"); + scanf("%d",&raindeers); + while(raindeers % 2 == 0){ + printf("Incert correct number of raindeers.\n"); + scanf("%d",&raindeers); + } + for (i = 0; i < raindeers; ++i) + { + scanf("%d",&num[i]); + } + + for (i = 0; i < raindeers; ++i) + { + for (j = 0; j < raindeers; ++j) + { + if(num[i] == num[j]){ + a = 1; + } + else{ + a = 0; + } + } + if(a == 0){ + printf("%d\n", num[i]); + break; + } + } + + return 0; +} +