Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int t; //no of test cases
- cin>>t;
- while(t--)
- {
- string s; // input string
- cin>>s;
- int arr1[26];
- int arr2[26];
- for(int i=0;i<26;i++) //initialize array to zero
- {
- arr1[i]=0;
- arr2[i]=0;
- }
- int length = 0;
- length=s.length();
- if(length>=2 && length<=1000)
- {
- if(length%2==0)
- {
- for(int i=0;i<length/2;i++)
- {
- arr1[(int(s[i])-97)]++; //convert ascii into decimal
- }
- for(int i=length/2;i<length;i++)
- {
- arr2[(int(s[i])-97)]++;
- }
- }
- else
- {
- for(int i=0;i<length/2;i++)
- {
- arr1[(int(s[i])-97)]++;
- }
- for(int i=(length+1)/2;i<length;i++)
- {
- arr2[(int(s[i])-97)]++;
- }
- }
- int flag =0;
- for(int i=0;i<26;i++) // check whether bothh arrays are equal
- {
- if(arr1[i]!=arr2[i])
- {
- cout<<"NO"<<"\n";
- break;
- flag=0;
- }
- else
- {
- flag=1;
- }
- }
- if (flag==1)
- cout<<"YES"<<"\n";
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment