-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathStringisPangrammaticLipogram.java
75 lines (62 loc) · 1.54 KB
/
StringisPangrammaticLipogram.java
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Java program to check if a string
// is Pangrammatic Lipogram
import java.util.*;
class GFG
{
// collection of letters
static String alphabets = "abcdefghijklmnopqrstuvwxyz";
/*
Category No of letters unmatched
Pangram 0
Lipogram >1
Pangrammatic Lipogram 1
*/
// function to check for a Pangrammatic Lipogram
static void panLipogramChecker(char []s)
{
// convert string to lowercase
for(int i = 0; i < s.length; i++)
{
s[i] = Character.toLowerCase(s[i]);
}
// variable to keep count of all the letters
// not found in the string
int counter = 0 ;
// traverses the string for every
// letter of the alphabet
for(int i = 0 ; i < 26 ; i++)
{
int pos = find(s, alphabets.charAt(i));
// if character not found in string
// then increment count
if(pos<0 || pos > s.length)
counter += 1;
}
if(counter == 0)
System.out.println("Pangram");
else if(counter >= 2)
System.out.println("Not a pangram but might a lipogram");
else
System.out.println("Pangrammatic Lipogram");
}
static int find(char[]arr, char c)
{
for(int i = 0; i < arr.length; i++)
{
if(c == arr[i])
return 1;
}
return -1;
}
// Driver program to test above function
public static void main(String []args)
{
char []str = "The quick brown fox jumped over the lazy dog".toCharArray();
panLipogramChecker(str);
str = "The quick brown fox jumps over the lazy dog".toCharArray();
panLipogramChecker(str);
str = "The quick brown fox jump over the lazy dog".toCharArray();
panLipogramChecker(str);
}
}
// This code is contributed by Rajput-Ji