We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0161400 commit 02b66c1Copy full SHA for 02b66c1
Strings/Anagram.java
@@ -0,0 +1,39 @@
1
+import java.util.Scanner;
2
+
3
+public class Anagram {
4
5
+ public static void main(String[] args) {
6
+ Scanner sc = new Scanner(System.in);
7
8
+ int t = sc.nextInt();
9
+ String s1,s2;
10
+ int[] arr,arr1;
11
12
+ for(int i=0;i<t;i++) {
13
+ int c = 0;
14
+ s1 = sc.next();
15
+ s2 = sc.next();
16
+ if(s1.length() == s2.length()) {
17
+ arr = new int[26];
18
+ arr1 = new int[26];
19
+ for(int j=0;j<s1.length();j++) {
20
+ arr[s1.charAt(j) - 'a']++;
21
+ arr1[s2.charAt(j) - 'a']++;
22
+ }
23
+ for(int j=0;j<arr.length;j++) {
24
+ if(arr[j] != arr1[j]) {
25
+ c = 1;
26
+ break;
27
28
29
+ } else {
30
31
32
+ if(c == 1) {
33
+ System.out.println("NO");
34
35
+ System.out.println("YES");
36
37
38
39
+}
0 commit comments