-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathanagram.cpp
More file actions
executable file
·53 lines (39 loc) · 797 Bytes
/
anagram.cpp
File metadata and controls
executable file
·53 lines (39 loc) · 797 Bytes
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
//
// anagram.cpp
// C++
//
// Created by Anish Mookherjee on 20/03/20.
// Copyright © 2020 Anish Mookherjee. All rights reserved.
//
#include <iostream>
#include <cstring>
using namespace std;
bool areAnagram(string str1, string str2)
{
int n1 = str1.length();
int n2 = str2.length();
if (n1 != n2)
return false;
sort(str1.begin(), str1.end());
sort(str2.begin(), str2.end());
for (int i = 0; i < n1; i++)
if (str1[i] != str2[i])
return false;
return true;
}
int main()
{
int n;
cin>>n;
while(n--)
{
string str1;
string str2;
cin>>str1>>str2;
if (areAnagram(str1, str2))
cout << "YES"<<endl;
else
cout << "NO"<<endl;
}
return 0;
}