|
| 1 | +#include <stdio.h> |
| 2 | +#include <string.h> |
| 3 | +#include <math.h> |
| 4 | +#include <stdlib.h> |
| 5 | +//https://thehuxley.com/problem/316/code-editor/?quizId=6236 |
| 6 | +/* |
| 7 | +Valor = (Posição no alfabeto) + (Elemento de entrada) + (Posição do elemento) |
| 8 | +Valor = %c - 48 + [numero da linha] + posição do elemento dentro do array de numero [] |
| 9 | +*/ |
| 10 | +#define DEBUG if(0) |
| 11 | +int hash(char alphabet, int lineNum, int elemPos) |
| 12 | +{ |
| 13 | + if (alphabet == '\n') return 0; |
| 14 | + DEBUG printf("[%c] = %d\n",alphabet,(alphabet-65) + lineNum + elemPos); |
| 15 | + return (alphabet-65) + lineNum + elemPos; |
| 16 | +} |
| 17 | +int preHash(char input[], int lineNum, int lenght) |
| 18 | +{ |
| 19 | + int pass = 0; |
| 20 | + for (int i = 0; i < lenght; i++) |
| 21 | + { |
| 22 | + pass = pass + hash(input[i],lineNum,i); |
| 23 | + } |
| 24 | + DEBUG printf("line = [%d] | pass = [%d]\n",lineNum,pass); |
| 25 | + return pass; |
| 26 | +} |
| 27 | +int function(int lines) //CBA |
| 28 | +{ int pass = 0, total = 0, len = 0; |
| 29 | + char input[51]; |
| 30 | + getchar(); |
| 31 | + for (int i = 0; i < lines; i++) |
| 32 | + { |
| 33 | + DEBUG printf("#########################\n"); |
| 34 | + gets(input); |
| 35 | + len = strlen(input); |
| 36 | + //if(input[len-1] != '\n') strcat(input,"\n"); |
| 37 | + DEBUG printf("len = [%d]\n",len); |
| 38 | + DEBUG printf("LINHA %d = {%s}\n",i,input); |
| 39 | + total = preHash(input, i, len) + total; |
| 40 | + DEBUG printf("TOTAL = [%d]\n",total); |
| 41 | + } |
| 42 | + return total; |
| 43 | +} |
| 44 | +int main() { |
| 45 | + int cases, ans, lines; |
| 46 | + scanf("%d",&cases); |
| 47 | + for (int i = 0; i < cases; i++) |
| 48 | + { |
| 49 | + DEBUG printf("------------------------ CASO [%d] ---------------------\n",i+1); |
| 50 | + scanf("%d",&lines); |
| 51 | + DEBUG printf("lines = [%d]\n",lines); |
| 52 | + ans = function(lines); |
| 53 | + printf("%d\n",ans); |
| 54 | + } |
| 55 | + |
| 56 | + return 0; |
| 57 | +} |
| 58 | + |
| 59 | +// 5 |
| 60 | +// 2 |
| 61 | +// CBA |
| 62 | +// DDD |
| 63 | +// 1 |
| 64 | +// Z |
| 65 | +// 6 |
| 66 | +// A |
| 67 | +// B |
| 68 | +// C |
| 69 | +// D |
| 70 | +// E |
| 71 | +// F |
| 72 | +// 6 |
| 73 | +// ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| 74 | +// ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| 75 | +// ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| 76 | +// ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| 77 | +// ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| 78 | +// ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| 79 | +// 1 |
| 80 | +// ZZZZZZZZZZ |
0 commit comments