Skip to content

Commit ab1051f

Browse files
authored
Merge pull request ephremdeme#113 from bhubhanshu/master
Added C# code for checking anagrams
2 parents b65a4f8 + 56b9249 commit ab1051f

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Anagram/check_anagrams.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace ConsoleApp1
5+
{
6+
class check_anagrams
7+
{
8+
static void Main(string[] args)
9+
{
10+
Console.WriteLine("Enter two strings in two different lines: ");
11+
string a = Console.ReadLine();
12+
string b = Console.ReadLine();
13+
int[] a_frequency = new int[256];
14+
int[] b_frequency = new int[256];
15+
bool isAnagram = true;
16+
foreach (char c in a)
17+
{
18+
a_frequency[(int)c]++;
19+
}
20+
foreach (char c in b)
21+
{
22+
b_frequency[(int)c]++;
23+
}
24+
for(int i = 0; i < 256; i++)
25+
{
26+
if(a_frequency[i] != b_frequency[i])
27+
{
28+
isAnagram = false;
29+
break;
30+
}
31+
}
32+
if (isAnagram)
33+
{
34+
Console.WriteLine(a + " and " + b + " are anagrams.");
35+
}
36+
else
37+
{
38+
Console.WriteLine(a + " and " + b + " are NOT anagrams.");
39+
}
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)