Skip to content

Commit 2bf2723

Browse files
Anagram.cpp
1 parent dec706f commit 2bf2723

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Placement/String/Anagram.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//Checking weather one string is anagram of other.(Permutation of one another)
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
int main()
5+
{
6+
string s1,s2;
7+
int cnt1[26]={0};
8+
int cnt2[26]={0};
9+
cin>>s1>>s2;
10+
for(int i=0;s1[i];i++)
11+
{
12+
cnt1[s1[i]-'a']++;
13+
}
14+
for(int i=0;s2[i];i++)
15+
{
16+
cnt2[s2[i]-'a']++;
17+
}
18+
int f=0;
19+
for(int i=0;i<26;i++)
20+
{
21+
if(cnt1[i]!=cnt2[i])
22+
{
23+
f=1;
24+
break;
25+
}
26+
}
27+
if(f==1)
28+
{
29+
cout<<"Not Anagram\n";
30+
}
31+
else
32+
cout<<"Anagram\n";
33+
return 0;
34+
}

0 commit comments

Comments
 (0)