Created
March 6, 2019 21:19
-
-
Save maciektr/c8855556d9179c5244b8827c66353229 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
const int K = (int)'z'+1; | |
bool anagram(int *a, int *b,const int N){ | |
int tab[K]; | |
for(int i = 0; i<K; i++) | |
tab[i] = 0; | |
int changed=0; | |
for(int i = 0; i<N; i++){ | |
if(tab[a[i]]==0) | |
changed++; | |
tab[a[i]]++; | |
} | |
for(int i = 0; i<N; i++){ | |
tab[b[i]]--; | |
if(tab[b[i]]==0) | |
changed--; | |
} | |
return (changed==0); | |
} | |
int main(){ | |
string input1, input2; | |
cin>>input1>>input2; | |
int n = (int)input1.size(); | |
int *a = new int[n]; | |
int *b = new int[n]; | |
for(int i = 0; i<n; i++){ | |
a[i] = (int)input1[i]; | |
b[i] = (int)input2[i]; | |
} | |
cout<<(anagram(a,b,n) ? "TAK":"NIE")<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment