#include <iostream>
#include <string>
using namespace std;
int main()
{
int n;
string str;
string bitus;
string bajtus;
cin >> n;
getline(cin >> ws, bitus);
getline(cin >> ws, bajtus);
//changing
for (int j = 0; j < n-2; j++)
{
int letterBaj = (int)bajtus[j] - 97;
int indexBit = -1;
for(int i = j; i < n; i+=2)
{
int letterBit = (int)bitus[i] - 97;
if (letterBit == letterBaj)
{
indexBit = i;
break;
}
}
if(indexBit == -1)
{
cout << "NIE";
return 0;
}
if(indexBit == j)
{
continue;
}
int m = ((indexBit - j) / 2);
for (int i = 0; i < m; i++)
{
char temp = bitus[i + j];
bitus[i + j] = bitus[indexBit-i];
bitus[indexBit-i] = temp;
}
}
if (bitus == bajtus)
cout << "TAK";
else
cout << "NIE";
}
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 | #include <iostream> #include <string> using namespace std; int main() { int n; string str; string bitus; string bajtus; cin >> n; getline(cin >> ws, bitus); getline(cin >> ws, bajtus); //changing for (int j = 0; j < n-2; j++) { int letterBaj = (int)bajtus[j] - 97; int indexBit = -1; for(int i = j; i < n; i+=2) { int letterBit = (int)bitus[i] - 97; if (letterBit == letterBaj) { indexBit = i; break; } } if(indexBit == -1) { cout << "NIE"; return 0; } if(indexBit == j) { continue; } int m = ((indexBit - j) / 2); for (int i = 0; i < m; i++) { char temp = bitus[i + j]; bitus[i + j] = bitus[indexBit-i]; bitus[indexBit-i] = temp; } } if (bitus == bajtus) cout << "TAK"; else cout << "NIE"; } |
English