#include "bits/stdc++.h" #include <cstdio> using namespace std; bool isPalindrome = false; #define MAX_BUFFER 600000 char buffer1[MAX_BUFFER]; char buffer2[MAX_BUFFER]; char buffer0[MAX_BUFFER*2]; int wordBeginning; bool isContinuousPalindrome(char x[], int length) { for(int i = 0; i < length; i++) { if(x[i] != x[length-i-1]) return false; } return true; } bool doPartsComprisePalindrome(char x[], char y[], int length) { for(int i = 0; i < length; i++) { if(x[i] != y[length-i-1]) return false; } return true; } int len(int n) { int res = 0; do { res++; n /= 10; }while(n != 0); return res; } int main() { int n; scanf("%d", &n); wordBeginning = len(n)+1; if(n != 0 && n <= MAX_BUFFER*2) { cin.readsome(buffer0, n); isPalindrome = isContinuousPalindrome(buffer0, n); } else { if(n == 0) { fseek(stdin, wordBeginning, SEEK_SET); char a; int x = 0; while(scanf("%c", &a) == 1) { x++; } n = x; } clearerr (stdin); rewind(stdin); int pos; int k = 0; do { int interval = n - 2 * MAX_BUFFER * k; if(interval <= MAX_BUFFER*2) { pos = 0; fseek(stdin, MAX_BUFFER*k + wordBeginning, SEEK_SET); for(int i = 0; i < interval; i++) { buffer0[pos] = getchar(); pos++; } isPalindrome = isContinuousPalindrome(buffer0, interval); break; } else { pos = 0; fseek(stdin, MAX_BUFFER*k + wordBeginning, SEEK_SET); for(int i = 0; i < MAX_BUFFER; i++) { buffer1[pos] = getchar(); pos++; } pos = 0; fseek(stdin, n - MAX_BUFFER*(k+1) + wordBeginning, SEEK_SET); for(int i = 0; i < MAX_BUFFER; i++) { buffer2[pos] = getchar(); pos++; } isPalindrome = doPartsComprisePalindrome(buffer1, buffer2, MAX_BUFFER); if(!isPalindrome) break; } k++; }while(1); } if(isPalindrome) cout << "TAK" << endl; else cout << "NIE" << endl; 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #include "bits/stdc++.h" #include <cstdio> using namespace std; bool isPalindrome = false; #define MAX_BUFFER 600000 char buffer1[MAX_BUFFER]; char buffer2[MAX_BUFFER]; char buffer0[MAX_BUFFER*2]; int wordBeginning; bool isContinuousPalindrome(char x[], int length) { for(int i = 0; i < length; i++) { if(x[i] != x[length-i-1]) return false; } return true; } bool doPartsComprisePalindrome(char x[], char y[], int length) { for(int i = 0; i < length; i++) { if(x[i] != y[length-i-1]) return false; } return true; } int len(int n) { int res = 0; do { res++; n /= 10; }while(n != 0); return res; } int main() { int n; scanf("%d", &n); wordBeginning = len(n)+1; if(n != 0 && n <= MAX_BUFFER*2) { cin.readsome(buffer0, n); isPalindrome = isContinuousPalindrome(buffer0, n); } else { if(n == 0) { fseek(stdin, wordBeginning, SEEK_SET); char a; int x = 0; while(scanf("%c", &a) == 1) { x++; } n = x; } clearerr (stdin); rewind(stdin); int pos; int k = 0; do { int interval = n - 2 * MAX_BUFFER * k; if(interval <= MAX_BUFFER*2) { pos = 0; fseek(stdin, MAX_BUFFER*k + wordBeginning, SEEK_SET); for(int i = 0; i < interval; i++) { buffer0[pos] = getchar(); pos++; } isPalindrome = isContinuousPalindrome(buffer0, interval); break; } else { pos = 0; fseek(stdin, MAX_BUFFER*k + wordBeginning, SEEK_SET); for(int i = 0; i < MAX_BUFFER; i++) { buffer1[pos] = getchar(); pos++; } pos = 0; fseek(stdin, n - MAX_BUFFER*(k+1) + wordBeginning, SEEK_SET); for(int i = 0; i < MAX_BUFFER; i++) { buffer2[pos] = getchar(); pos++; } isPalindrome = doPartsComprisePalindrome(buffer1, buffer2, MAX_BUFFER); if(!isPalindrome) break; } k++; }while(1); } if(isPalindrome) cout << "TAK" << endl; else cout << "NIE" << endl; return 0; } |