forked from Red-0111/Anything-Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnagram.cpp
More file actions
58 lines (39 loc) · 1.03 KB
/
Anagram.cpp
File metadata and controls
58 lines (39 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution
{
public:
//Function is to check whether two strings are anagram of each other or not.
bool isAnagram(string a, string b){
// if(a.length()!=b.length()) return false;
// sort(a.begin(),a.end());
// sort(b.begin(),b.end());
// return (a==b);
const int CHAR = 256;
if(a.length()!=b.length()) return false;
char count[CHAR] = {0};
for(int i=0;i<a.length();i++){
count[a[i]]++;
count[b[i]]--;
}
for(int i=0;i<CHAR;i++){
if(count[i]!=0)
return false;
}
return true;
}
};
//{ Driver Code Starts.
int main() {
int t;
cin >> t;
while(t--){
string c, d;
cin >> c >> d;
Solution obj;
if(obj.isAnagram(c, d)) cout << "YES" << endl;
else cout << "NO" << endl;
}
}
// } Driver Code Ends