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
107
108
109
110
#include <iostream>
using namespace std;
bool tablica[300000];
int main()
{
    int n;
    cin >> n;
    int i = 299999;
    while (i != -1)
    {
        tablica[i] = false;
        i--;
    }
    char bit[300001];
    char bajt[300001];
    int sprawdzaczka=0;
    cin >> bit>>bajt;
    /*cout << bit;
    if (bit == bajt) 
    {
        cout << bajt;
    }*/
    /*if (bit == bajt) 
    {
        cout << "TAK";
    }*/
    /*int pkt = 0;*/
    int retN = n;
   /* while (n != 0) 
    {
        n--;
        if (bit[n] == bajt[n])
        {
            pkt++;
        }
    }*/
    string bitRet = bit;
    string bajtRet = bajt;
    n = retN;
    int nparz=n-2;
    int nparz2 = n-2;
    int parz = n-1;
    int parz2 = n - 1;
    int a = 0;
    if (n % 2 == 0) 
    {
        parz++;
        parz2++;
        nparz++;
        nparz2++;
    }
    int parzR = parz;
    int np = nparz;
    while (nparz2 != -1) 
    {
        while (nparz != -1)
        {
            int nparzRet = nparz;
            while((nparz > -1)&&(tablica[nparz]))
            {
                nparz -= 2;
            }
            if (nparz < 0) 
            {
                break;
            }
            if (bit[nparz] == bajt[nparz2])
            {
                tablica[nparz] = true;
                sprawdzaczka++;
                break;
            }
            nparz -= 2;
        }
        nparz = np;
        nparz2 -= 2;
    }
    while (parz2 != -2)
    {
        while (parz != -2)
        {
            int parzRet = parz;
            while ((parz > -1) && (tablica[parz]))
            {
                parz -= 2;
            }
            if (parz < 0)
            {
                break;
            }
            if (bit[parz] == bajt[parz2])
            {
                tablica[parz] = true;
                sprawdzaczka++;
                break;
            }
            parz -= 2;
        }
        parz = parzR;
        parz2 -= 2;
    }
    if (sprawdzaczka == n) 
    {
        cout << "TAK";
    }
    else 
    {
        cout << "NIE";
    }
}