forked from VivekDubey9/Competitive-Programming-Algos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
anagram.cpp
58 lines (45 loc) · 795 Bytes
/
anagram.cpp
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;
bool isAnagram(string str1, string str2)
{
int str1_size=str1.size();
int str2_size=str2.size();
int flag=0;
map<char,int>m;
for(int i=0;i<str1_size;i++)
{
m[str1[i]]++;
}
for(int i=0;i<str2_size;i++)
{
m[str2[i]]--;
}
for(auto i:m)
{
// cout<<i.first;
if(i.second!=0 || i.second<0)
{
// cout<<i.first;
flag=1;
}
}
if(flag==1)
{
return false;
}
else
return true;
}
int main()
{
string str1;
string str2;
cin>>str1>>str2;
bool result;
result=isAnagram(str1,str2);
if(result)
cout<<"Yes";
else
cout<<"No";
return 0;
}