File size: 969 Bytes
4559903 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #include <stdio.h>
#include <string.h>
typedef struct {
long hash, count;
char similar[4][200];
} occurance_t;
long hash(char *word) {
long i, sum = 42;
for (i = 0; i < strlen(word); ++i)
sum += word[i]*(i+1);
return sum;
}
int main() {
occurance_t words[3000];
char word[200];
long i, max_count = 0, k = 0;
while(max_count < 4) {
scanf("%s", word);
for (i = 0; i <= 3000; ++i) {
if (words[i].hash == hash(word)) {
strcpy(words[i].similar[++words[i].count], word);
if (words[i].count > max_count)
max_count = words[i].count;
break;
} else if (words[i].hash == 0) {
words[i].hash = hash(word);
words[i].count = 1;
strcpy(words[i].similar[words[i].count], word);
break;
}
}
++k;
}
for (i = 0; i < k ; ++i) {
if (words[i].count >= 2) {
printf("[%ld]", words[i].hash);
int j;
for (j = 0; j <= 4; ++j)
printf("%s ", words[i].similar[j]);
printf("\n");
}
}
return 0;
}
|