forked from Hacktoberfest-2021/2022_problem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanagram.cpp
More file actions
39 lines (38 loc) · 801 Bytes
/
anagram.cpp
File metadata and controls
39 lines (38 loc) · 801 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
char A[] = "depp";
char B[] = "deap";
int as1 = sizeof(A) / sizeof(A[0]);
int as2 = sizeof(B) / sizeof(B[0]);
int h[128] = {0}, i, j;
bool flag = false;
if (as1 != as2)
{
cout << "This are not Anagrams" << endl;
}
else
{
for (i = 0; A[i] != '\0'; i++)
{
h[A[i]]++;
}
for (j = 0; B[j] != '\0'; j++)
{
h[B[j]]--;
if (h[B[j]] < 0)
{
cout << "This are not Anagrams" << endl;
break;
}
}
if (B[j] == '\0')
{
cout << "This are Anagrams" << endl;
}
}
return 0;
}