radhikam14

LAPIN

Apr 1st, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int t; //no of test cases
  7.  
  8. cin>>t;
  9.  
  10.  
  11. while(t--)
  12. {
  13. string s; // input string
  14. cin>>s;
  15. int arr1[26];
  16. int arr2[26];
  17.  
  18. for(int i=0;i<26;i++) //initialize array to zero
  19. {
  20. arr1[i]=0;
  21. arr2[i]=0;
  22. }
  23.  
  24. int length = 0;
  25. length=s.length();
  26. if(length>=2 && length<=1000)
  27. {
  28. if(length%2==0)
  29. {
  30. for(int i=0;i<length/2;i++)
  31. {
  32. arr1[(int(s[i])-97)]++; //convert ascii into decimal
  33.  
  34. }
  35. for(int i=length/2;i<length;i++)
  36. {
  37. arr2[(int(s[i])-97)]++;
  38.  
  39. }
  40. }
  41. else
  42. {
  43.  
  44. for(int i=0;i<length/2;i++)
  45. {
  46. arr1[(int(s[i])-97)]++;
  47.  
  48. }
  49. for(int i=(length+1)/2;i<length;i++)
  50. {
  51. arr2[(int(s[i])-97)]++;
  52.  
  53. }
  54. }
  55.  
  56. int flag =0;
  57. for(int i=0;i<26;i++) // check whether bothh arrays are equal
  58. {
  59. if(arr1[i]!=arr2[i])
  60. {
  61. cout<<"NO"<<"\n";
  62. break;
  63. flag=0;
  64. }
  65. else
  66. {
  67. flag=1;
  68. }
  69.  
  70. }
  71.  
  72.  
  73. if (flag==1)
  74. cout<<"YES"<<"\n";
  75.  
  76.  
  77.  
  78. }
  79. }
  80. return 0;
  81. }
Add Comment
Please, Sign In to add comment