-
Notifications
You must be signed in to change notification settings - Fork 16
/
Anagram.cpp
48 lines (38 loc) · 824 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
//Code for checking if two strings are anagram or not
//Anagram strings means we can form one string by arranging the characters of another string.
#include<iostream>
using namespace std;
int main()
{
char str1[100],str2[100];
int first[26]={0}, second[26]={0}, c=0, flag=0;
cout<<"Enter First String: ";
gets(str1);
cout<<"Enter Second String: ";
gets(str2);
while(str1[c] != '\0')
{
first[str1[c]-'a']++;
c++;
}
c=0;
while(str2[c] != '\0')
{
second[str2[c]-'a']++;
c++;
}
for(c=0;c<26;c++)
{
if(first[c] != second[c])
flag=1;
}
if(flag == 0)
{
cout<<"Strings are anagram.";
}
else
{
cout<<"Strings are not anagram.";
}
return 0;
}