#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; string a,b; cin>>n>>a>>b; string even[2]; int count[2][26]={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; string odd[2]; int evenNum=0; int oddNum=0; for(int i=0;i<n;i++) { if(i%2 ==0) { even[0]+=a[i]; even[1]+=b[i]; evenNum++; } else { odd[0]+=a[i]; odd[1]+=b[i]; oddNum++; } } for(int i=0;i<evenNum;i++) { count[0][even[1][i]-'a']++; } for(int i=0;i<oddNum;i++) { count[1][odd[1][i]-'a']++; } int i=0; bool ok=true; while(evenNum!=0) { if(count[0][even[0][i]-'a']>0) { count[0][even[0][i]-'a']--; evenNum--; } else { ok=false; break; } i++; } i=0; while(ok && oddNum!=0) { if(count[1][odd[0][i]-'a']>0) { count[1][odd[0][i]-'a']--; oddNum--; } else { ok=false; break; } i++; } if(ok) cout<<"TAK"; else cout<<"NIE"; 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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; string a,b; cin>>n>>a>>b; string even[2]; int count[2][26]={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; string odd[2]; int evenNum=0; int oddNum=0; for(int i=0;i<n;i++) { if(i%2 ==0) { even[0]+=a[i]; even[1]+=b[i]; evenNum++; } else { odd[0]+=a[i]; odd[1]+=b[i]; oddNum++; } } for(int i=0;i<evenNum;i++) { count[0][even[1][i]-'a']++; } for(int i=0;i<oddNum;i++) { count[1][odd[1][i]-'a']++; } int i=0; bool ok=true; while(evenNum!=0) { if(count[0][even[0][i]-'a']>0) { count[0][even[0][i]-'a']--; evenNum--; } else { ok=false; break; } i++; } i=0; while(ok && oddNum!=0) { if(count[1][odd[0][i]-'a']>0) { count[1][odd[0][i]-'a']--; oddNum--; } else { ok=false; break; } i++; } if(ok) cout<<"TAK"; else cout<<"NIE"; return 0; } |