File size: 1,083 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
#include <string.h>


struct occurance_t {
	long hash;
	int count;
};

long hash(char *);

int main() {

	char word[200];
	long arr[3000][2];
	long curr_hash;
	int i, max = 0, t_word;
	struct occurance_t words;

	for(i = 0; i < 3000; i++) {
		arr[i][0] = 0;
		arr[i][1] = 0;
	} 

	while(1) {

		scanf("%99s", word);

		if(word[0] == 'v' &&
		   word[1] == 's' &&
		   word[2] == 'm' &&
		   word[3] == 'i' &&
		   word[4] == 's' && 
		   word[5] == 'a' &&
		   word[6] == 'l') break;

		curr_hash = hash(word);

		for(i = 0; i < 3000; i++) {
			if(arr[i][0] == 0) 
			{
				arr[i][0] = curr_hash;
				arr[i][1]++;
				i = 3000;
			}
			else if(curr_hash == arr[i][0]) 
			{
				arr[i][1]++;
				i = 3000;
			}
		}

	}

	for(i = 0; i < 3000; i++) {
		if(arr[i][1] > max) 
		{
			max = arr[i][1];
			t_word = arr[i][0];
		} 
	}

	words.hash = t_word;
	words.count = max;

	printf("%d %ld", words.count, words.hash);

	return 0;
}

long hash(char *word) {
	long hash = 42;
	int i;

	for(i = 0; i < strlen(word); i++) {
		hash += word[i] * (i + 1);
	}

	return hash;
}