-
Notifications
You must be signed in to change notification settings - Fork 1
/
arrayhash.c
51 lines (44 loc) · 973 Bytes
/
arrayhash.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int func_hash(int indice, int cont_entrada, int pos)
{
int key=indice+cont_entrada+pos;
return key;
}
int alfabetocont(char alfabeto[25], char letra)
{
int i=0;
for ( i = 0; i < 25; i++)
{
if(letra==alfabeto[i])
{
return i;
}
}
}
int main()
{
int casos, total, entradas, cont, i, n, posalfa;
char alfabeto[25]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char palavra[100];
scanf("%d", &casos);
while (casos--)
{
total=0;
cont=0;
scanf("%d", &entradas);
while (entradas--)
{
scanf("%s", palavra);
n=strlen(palavra);
for ( i = 0; i < n; i++)
{
posalfa=alfabetocont(alfabeto, palavra[i]);
total=total+func_hash(i, cont, posalfa);
}
cont++;
}
printf("%d\n", total);
}
}