#include <stdio.h> #include <stdbool.h> #include <string> #include <algorithm> using namespace std; bool ok(int *a, int *b) { for (int i = 0; i < 36; i++) { if (a[i] != a[i + 40]) return false; if (b[i] != b[i + 40]) return false; } return true; } int main() { int n; scanf("%d\n", &n); char *bit = new char[n + 1]; char *baj = new char[n + 1]; scanf("%s\n", bit); scanf("%s\n", baj); string sbit(bit); string sbaj(baj); if (sbit == sbaj) { printf("TAK"); return 0; } std::sort(sbit.begin(), sbit.end()); std::sort(sbaj.begin(), sbaj.end()); if (sbit != sbaj) { printf("NIE"); return 0; } int parz[2*40] = {0}; int nparz[2*40] = {0}; for (int i = 0; i < n; i++) { if (i % 2 == 0) { parz[ bit[i] - 'a']++; parz[40 + baj[i] - 'a']++; } else { nparz[ bit[i] - 'a']++; nparz[40 + baj[i] - 'a']++; } } //printf("%s\n", sbit.c_str()); //printf("%s\n", sbaj.c_str()); printf(ok(parz,nparz) ? "TAK" : "NIE"); //caab //aabc return 0; } //abcd //bacd
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 | #include <stdio.h> #include <stdbool.h> #include <string> #include <algorithm> using namespace std; bool ok(int *a, int *b) { for (int i = 0; i < 36; i++) { if (a[i] != a[i + 40]) return false; if (b[i] != b[i + 40]) return false; } return true; } int main() { int n; scanf("%d\n", &n); char *bit = new char[n + 1]; char *baj = new char[n + 1]; scanf("%s\n", bit); scanf("%s\n", baj); string sbit(bit); string sbaj(baj); if (sbit == sbaj) { printf("TAK"); return 0; } std::sort(sbit.begin(), sbit.end()); std::sort(sbaj.begin(), sbaj.end()); if (sbit != sbaj) { printf("NIE"); return 0; } int parz[2*40] = {0}; int nparz[2*40] = {0}; for (int i = 0; i < n; i++) { if (i % 2 == 0) { parz[ bit[i] - 'a']++; parz[40 + baj[i] - 'a']++; } else { nparz[ bit[i] - 'a']++; nparz[40 + baj[i] - 'a']++; } } //printf("%s\n", sbit.c_str()); //printf("%s\n", sbaj.c_str()); printf(ok(parz,nparz) ? "TAK" : "NIE"); //caab //aabc return 0; } //abcd //bacd |