#include <bits/stdc++.h> using namespace std; #define A 97 void wczytaj(int *tab, int n) { int c; for (int i = 0; i < n; ++i) { c = getchar(); tab[i] = c - A; } } bool czy_te_same(int *tab1, int *tab2, int n) { int licz1[26] = {}, licz2[26] = {}; for (int i = 0; i < n; ++i) { licz1[tab1[i]]++; licz2[tab2[i]]++; } for (int i = 0; i < 26; ++i) { if (licz1[i] != licz2[i]) return false; } return true; } bool sprawdz(int *tab1, int *tab2, int n) { if(!czy_te_same(tab1,tab2,n)) return false; vector<vector<int>> v1, v2; for (int i = 0; i < 26; ++i) { vector<int> a, b; v1.push_back(a); v2.push_back(b); } for (int i = 0; i < n; ++i) { if(tab1[i] != tab2[i]) { v1[tab1[i]].push_back(i); v2[tab2[i]].push_back(i); } } for (int i = 0; i < 26; ++i) { for (int j = 0; j < (int) v1[i].size(); ++j) { for (int k = 0; k < (int) v2[i].size(); ++k) { if (abs(v1[i][j] - v2[i][k]) % 2 == 1) return false; } } } return true; } int main() { int n; scanf("%d\n", &n); int *tab1, *tab2; tab1 = new int[n]; tab2 = new int[n]; wczytaj(tab1, n); getchar(); wczytaj(tab2, n); (sprawdz(tab1, tab2, n)) ? cout << "TAK\n" : cout << "NIE\n"; delete[] tab1; delete[] tab2; 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 | #include <bits/stdc++.h> using namespace std; #define A 97 void wczytaj(int *tab, int n) { int c; for (int i = 0; i < n; ++i) { c = getchar(); tab[i] = c - A; } } bool czy_te_same(int *tab1, int *tab2, int n) { int licz1[26] = {}, licz2[26] = {}; for (int i = 0; i < n; ++i) { licz1[tab1[i]]++; licz2[tab2[i]]++; } for (int i = 0; i < 26; ++i) { if (licz1[i] != licz2[i]) return false; } return true; } bool sprawdz(int *tab1, int *tab2, int n) { if(!czy_te_same(tab1,tab2,n)) return false; vector<vector<int>> v1, v2; for (int i = 0; i < 26; ++i) { vector<int> a, b; v1.push_back(a); v2.push_back(b); } for (int i = 0; i < n; ++i) { if(tab1[i] != tab2[i]) { v1[tab1[i]].push_back(i); v2[tab2[i]].push_back(i); } } for (int i = 0; i < 26; ++i) { for (int j = 0; j < (int) v1[i].size(); ++j) { for (int k = 0; k < (int) v2[i].size(); ++k) { if (abs(v1[i][j] - v2[i][k]) % 2 == 1) return false; } } } return true; } int main() { int n; scanf("%d\n", &n); int *tab1, *tab2; tab1 = new int[n]; tab2 = new int[n]; wczytaj(tab1, n); getchar(); wczytaj(tab2, n); (sprawdz(tab1, tab2, n)) ? cout << "TAK\n" : cout << "NIE\n"; delete[] tab1; delete[] tab2; return 0; } |