fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. static String equal( String s1,String s2)
  12. {
  13. //maps for odd and even parts of both s1,s2 strings
  14. Map<Character,Integer> m1=new HashMap<>();
  15. Map<Character,Integer> m2=new HashMap<>();
  16. Map<Character,Integer> m3=new HashMap<>();
  17. Map<Character,Integer> m4=new HashMap<>();
  18.  
  19. //putting chars of s1 of both odd and even idx in maps
  20. for(int i=0;i<s1.length();i++)
  21. {
  22. char ch=s1.charAt(i);
  23.  
  24. //if idx is odd we will put character in map 1
  25. if(i%2!=0)
  26. m1.put(ch,m1.getOrDefault(ch,0)+1);
  27.  
  28. //if idx is even we will put char in map 2
  29. else
  30. m2.put(ch,m2.getOrDefault(ch,0)+1);
  31. }
  32.  
  33. //putting odd and even idx chars of s2 in map
  34. for(int i=0;i<s2.length();i++)
  35. {
  36. char ch=s2.charAt(i);
  37. //putting odd idx chars of s2 in map 3
  38. if(i%2!=0)
  39. m3.put(ch,m3.getOrDefault(ch,0)+1);
  40.  
  41. //putting eve idx parts of s3 in map4
  42. else
  43. m4.put(ch,m4.getOrDefault(ch,0)+1);
  44.  
  45. }
  46.  
  47. boolean ans1,ans2;
  48. ans1=true;
  49. ans2=true;
  50.  
  51. //checking odd idx chars in s1,s2
  52. for(char ch:m1.keySet())
  53. {
  54. if(m1.getOrDefault(ch,0)!=m3.getOrDefault(ch,0))
  55. {
  56. ans1=false;
  57. break;
  58. }
  59. }
  60.  
  61. // checking eve idx chars in s1,s2
  62. for(char ch:m2.keySet())
  63. {
  64. if(m2.getOrDefault(ch,0)!=m4.getOrDefault(ch,0))
  65. {
  66. ans2=false;
  67. break;
  68. }
  69. }
  70.  
  71. if(ans1==ans2)
  72. return "Yes";
  73. else
  74. return "No";
  75.  
  76. }
  77. public static void main (String[] args) throws java.lang.Exception
  78. {
  79. // your code goes here
  80. Scanner sc=new Scanner(System.in);
  81. int n=sc.nextInt();
  82. List<String> l1=new ArrayList<>();
  83. List<String> l2=new ArrayList<>();
  84.  
  85. //reading all string in a array
  86. for(int i=1;i<=n;i++)
  87. {
  88. String s=sc.next();
  89. l1.add(s);
  90. }
  91.  
  92. //reading all strings of b array
  93. for(int i=1;i<=n;i++)
  94. {
  95. String s=sc.next();
  96. l2.add(s);
  97. }
  98.  
  99.  
  100. for(int i=0;i<n;i++)
  101. System.out.println(equal(l1.get(i),l2.get(i)));
  102. }
  103. }
  104.  
Success #stdin #stdout 0.11s 54652KB
stdin
1
abcd
cdab
stdout
Yes