diff --git a/2015-2016/B/13/08/task1.c b/2015-2016/B/13/08/task1.c new file mode 100644 index 00000000..7a5405c4 --- /dev/null +++ b/2015-2016/B/13/08/task1.c @@ -0,0 +1,39 @@ +#include +#include + +long hash(char *); + +int main(){ + +char word[200]; + +scanf("%s", word); + + + long hash_counter; + hash_counter = hash(&word[0]); + +printf("%ld", hash_counter); + + +return 0; +} + +long hash(char *word){ + +int counter; + +int len_word = strlen(word); + + +long hash_counter = 42; + + +for(counter = 0; counter < len_word; counter++) + { + hash_counter += word[counter] * (counter + 1); + } + +return hash_counter; + +} diff --git a/2015-2016/B/13/08/task2.c b/2015-2016/B/13/08/task2.c new file mode 100644 index 00000000..0ac886a9 --- /dev/null +++ b/2015-2016/B/13/08/task2.c @@ -0,0 +1,83 @@ +#include +#include + +typedef struct occurance_t{ + +int times; +long hash_word; + +}occurance_t; + + +long hash(char *); + + int main(){ + + int counter = 0; + char word[200]; + occurance_t array_words[3000]; + + scanf("%s", word); + + for(;strcmp(word,"vsmisal") != 0; counter++) + { + array_words[counter].hash_word = hash(&word[0]); + + array_words[counter].times = 1; + + int the_same_hash = 0; + int second_counter; + for(second_counter = 0; second_counter < counter; second_counter++) + { + + if(array_words[counter].hash_word == array_words[second_counter].hash_word) + { + array_words[second_counter].times++; + the_same_hash = 1; + } + + if(the_same_hash == 0 && second_counter == (counter-1) ) + { + array_words[counter].times = 1; + } + } + + scanf("%s", word); + } + + int help_times = array_words[counter].times; + long help_counter = counter; + + for(; counter > 0 ; counter--) + { + + if(array_words[counter].times < array_words[counter - 1].times) + { + help_times = array_words[counter - 1].times; + help_counter = counter - 1; + } + } + + printf("%d %ld",help_times,array_words[help_counter].hash_word); + return 0; + } + + + +long hash(char *word){ + +int counter; + +int len_word = strlen(word); + +long hash_counter = 42; + + +for(counter = 0; counter < len_word; counter++) + { + hash_counter += word[counter] * (counter + 1); + } + +return hash_counter; + +} diff --git a/2015-2016/B/13/08/task3.c b/2015-2016/B/13/08/task3.c new file mode 100644 index 00000000..a75a06bd --- /dev/null +++ b/2015-2016/B/13/08/task3.c @@ -0,0 +1,78 @@ +#include +#include + +typedef struct occurance_t{ + +int times; +long hash_word; +char words[3000][200]; + +}occurance_t; + + +long hash(char *); + + int main(){ + + int counter = 0; + char word[200]; + occurance_t array_words[3000]; + + int how_hash = 0; + + scanf("%s", word); + + for(;how_hash < 4; counter++) + { + array_words[counter].hash_word = hash(&word[0]); + + array_words[counter].times = 1; + + + int second_counter; + for(second_counter = 0; second_counter < counter; second_counter++) + { + + if(array_words[counter].hash_word == array_words[second_counter].hash_word) + { + array_words[second_counter].times++; + + if(how_hash >= 4) break; + how_hash++; + + } + + if(how_hash == 0 && second_counter == (counter-1) ) + { + array_words[counter].times = 1; + + } + } + + scanf("%s", word); + } + + return 0; + } + + + +long hash(char *word){ + +int counter; + +int len_word = strlen(word); + +long hash_counter = 42; + + +for(counter = 0; counter < len_word; counter++) + { + + hash_counter += word[counter] * (counter + 1); + + } + +return hash_counter; + +}