-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #353 from dhruv007patel/patch-1
Add Pangram.cs
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
class Pangram{ | ||
|
||
public static bool checkPangram (string str) | ||
{ | ||
|
||
// Create a hash table to mark the | ||
// characters present in the string | ||
// By default all the elements of | ||
// mark would be false. | ||
bool[] mark = new bool[26]; | ||
|
||
int index = 0; | ||
|
||
for (int i = 0; i < str.Length; i++) | ||
{ | ||
// If uppercase character, subtract 'A' to find index. | ||
if ('A' <= str[i] && | ||
str[i] <= 'Z') | ||
|
||
index = str[i] - 'A'; | ||
|
||
// If lowercase character,subtract 'a' to find index. | ||
else if('a' <= str[i] && | ||
str[i] <= 'z') | ||
|
||
index = str[i] - 'a'; | ||
|
||
// Marking current character as TRUE | ||
mark[index] = true; | ||
} | ||
|
||
// Return false if any character is missing | ||
for (int i = 0; i < 26; i++) | ||
if (mark[i] == false) | ||
return (false); | ||
|
||
// If all characters are present | ||
return (true); | ||
} | ||
|
||
//Main Function | ||
public static void Main() | ||
{ | ||
string str = "The quick brown fox jumps over the lazy dog"; | ||
|
||
if (checkPangram(str) == true) | ||
Console.WriteLine(str + " is a pangram."); | ||
else | ||
Console.WriteLine(str+ " is not a pangram."); | ||
|
||
} | ||
} |