forked from ambujraj/hacktoberfest2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPangram.cs
53 lines (40 loc) · 1.39 KB
/
Pangram.cs
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
49
50
51
52
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.");
}
}