#include <stdio.h> #include <stdlib.h> char set(unsigned int *S,unsigned int N,char c) { unsigned int n,o,G,g; n = (N-1) / 6; o = (N-1) % 6; G = c - 'a'; for (g = 0; g < o; g++) G *= 26; S[n] += G; // printf("Set: %u %u %u\n",n,o,G); return c; } char get(unsigned int *S,unsigned int N) { unsigned int n,o,G,g; n = N / 6; o = N % 6; G = S[n]; for (g = 0; g < o; g++) G /= 26; G %= 26; // printf("Get: %u %u %u %u\n",N,n,o,G); return 'a'+G; } int main() { char c; unsigned int N,n,MAX = 3333334,*S; scanf("%u",&MAX); //ignore if (MAX == 0) MAX = 3333334; S = (unsigned int*) malloc(MAX*sizeof(unsigned int)); N = 0; while ((c = getchar()) < 'a' || c > 'z'); do { // printf("%c %u\n",c,c-'a'); N++; set(S,N,c); } while ((c = getchar()) >= 'a' && c <= 'z'); n = 0; while (n < N/2 && get(S,n) == get(S,N-n-1)) n++; if (n == N/2) printf("TAK\n"); else printf("NIE\n"); free(S); return 0; }
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 | #include <stdio.h> #include <stdlib.h> char set(unsigned int *S,unsigned int N,char c) { unsigned int n,o,G,g; n = (N-1) / 6; o = (N-1) % 6; G = c - 'a'; for (g = 0; g < o; g++) G *= 26; S[n] += G; // printf("Set: %u %u %u\n",n,o,G); return c; } char get(unsigned int *S,unsigned int N) { unsigned int n,o,G,g; n = N / 6; o = N % 6; G = S[n]; for (g = 0; g < o; g++) G /= 26; G %= 26; // printf("Get: %u %u %u %u\n",N,n,o,G); return 'a'+G; } int main() { char c; unsigned int N,n,MAX = 3333334,*S; scanf("%u",&MAX); //ignore if (MAX == 0) MAX = 3333334; S = (unsigned int*) malloc(MAX*sizeof(unsigned int)); N = 0; while ((c = getchar()) < 'a' || c > 'z'); do { // printf("%c %u\n",c,c-'a'); N++; set(S,N,c); } while ((c = getchar()) >= 'a' && c <= 'z'); n = 0; while (n < N/2 && get(S,n) == get(S,N-n-1)) n++; if (n == N/2) printf("TAK\n"); else printf("NIE\n"); free(S); return 0; } |