File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments