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
#include <iostream>

using namespace std;

int main() {
    int toysQuantity;
    cin >> toysQuantity;

    string s1, s2;
    cin >> s1;
    cin >> s2;

    for (int i = 0; i < toysQuantity; i++) {

        bool isFine = false; // flag

        if (s1[i] == s2[i]) {
            isFine = true;
        } else {

            for (int j = i + 2; j < toysQuantity; j += 2) {
                if (s2[i] == s1[j]) {
                    //cout << "Da się: " << s1[i] << "[" << i << "]" << ", " << s1[j] << "[" << j << "]" << endl;

                    int requiredSwaps = (j - i) / 2;

                    //cout << "Przed: " << s1 << "  ----  ";
                    for (int k = 0; k < requiredSwaps; k++) {
                        char temp = s1[i + k];
                        s1[i + k] = s1[j - k];
                        s1[j - k] = temp;
                    }
                    //cout << "Po: " << s1 << endl;

                    isFine = true;

                    break;
                }

            }
        }  

        if (!isFine) {
            cout << "NIE";
            exit(0);
        }
    }

    cout << "TAK";
}