Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Homework 01 #883

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions 2015-2016/B/13/08/task1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include<stdio.h>
#include<string.h>

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;

}
83 changes: 83 additions & 0 deletions 2015-2016/B/13/08/task2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include<stdio.h>
#include<string.h>

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;

}
78 changes: 78 additions & 0 deletions 2015-2016/B/13/08/task3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include<stdio.h>
#include<string.h>

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;

}