A string is a pangram if it contains all letters of the English alphabet, ascii['a'-'z']. Given a list of strings, determine if each one is a pangram or not. Return "1" if true and "0" if false.
Example
pangram = ['pack my box with five dozen liquor jugs', 'this is not a pangram']
the string 'pack my box with five dozen liquor jugs' is a pangram , because it contains all the letters 'a' through 'z' the string 'this is not a pangram' is not a pangram.Assemble a string of the two results, in order. The result is '10'.
Function Description Complete the function isPangram n the editor below.
isPangram has the following parameter(s):
string pangram[n]: an array of strings
Returns:
string: a string where each position represents the results of a test. Use '1' for true and '0' for false.
Constraints
1 ≤ n ≤ 100
Each string pangram[i] (where 0 ≤ i < n) is composed of lowercase letters and spaces.
1 ≤ length of pangram[i] ≤ 105
Input Format for Custom Testing
Input from stdin will be processed as follows and passed to the function.
The first line contains an integer n, the size of the array pangram.The next n lines each contain an element, pangram[i], where 0 ≤ i < n.
Sample Case 0
Sample Input 0
STDIN Function Parameters
----- -------------------
4 → pangram[] size n = 4
we promptly judged antique ivory buckles for the next prize → pangram[] = ["we promptly judged antique ivory buckles for the next prize",
we promptly judged antique ivory buckles for the prizes "we promptly judged antique ivory buckles for the prizes",
the quick brown fox jumps over the lazy dog "the quick brown fox jumps over the lazy dog",
the quick brown fox jump over the lazy dog "the quick brown fox jump over the lazy dog" ]
Sample Output 0
1010
Explanation 0
pangram[0] = True
pangram[1] = False
pangram[2] = True
pangram[3] = False
The strings pangram[0] and pangram[2] are pangrams, and the others are not.
The result is '1010'
Sample Case 1Sample Input 1
STDIN Function Parameters
----- -------------------
4 → pangram[] Size n = 4
cfchcfcvpalpqxenhbytcwazpxtthjumliiobcznbefnofyjfsrwfecxcbmoafes tnulqkvx
oxhctvhybtikkgeptqulzukfmmavacshugpouxoliggcomykdnfayayqutgwivwldrkp
gpecfrak zzaxrigltstcrdyhelhz rasrzibduaq cnpuommogatqem
hbybsegucruhxkebrvmrmwhweirx mbkluwhfapjtga liiylfphmzkq
Sample Output 1
0000
Explanation 1
pangram[0] = False
pangram[1] = False
pangram[2] = False
pangram[3] = False
No string is a pangram.
The result is '0000'
Solution:
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import java.util.*;
class Result {
/*
* Complete the 'isPangram' function below.
*
* The function is expected to return a STRING.
* The function accepts STRING_ARRAY pangram as parameter.
*/
public static boolean checkPangram(String str)
{
boolean[] mark = new boolean[26];
int index = 0;
for (int i = 0; i < str.length(); i++) {
if ('A' <= str.charAt(i) && str.charAt(i) <= 'Z')
index = str.charAt(i) - 'A';
else if ('a' <= str.charAt(i) && str.charAt(i) <= 'z')
index = str.charAt(i) - 'a';
else
continue;
mark[index] = true;
}
for (int i = 0; i <= 25; i++)
if (mark[i] == false)
return (false);
return (true);
}
public static String isPangram(List<String> pangram) {
String ar[]=new String [pangram.size()];
int j=0;
for (String str : pangram)
{
ar[j]=str;
System.out.println(ar[j]);
j++;
}
String str1="";
for(int k=0; k<pangram.size();k++)
{
String str=ar[k];
if (checkPangram(str) == true)
str1=str1+"1";
else
str1=str1+"0";
}
return str1;
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int pangramCount = Integer.parseInt(bufferedReader.readLine().trim());
List<String> pangram = IntStream.range(0, pangramCount).mapToObj(i -> {
try {
return bufferedReader.readLine();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
})
.collect(toList());
String result = Result.isPangram(pangram);
bufferedWriter.write(result);
bufferedWriter.newLine();
bufferedReader.close();
bufferedWriter.close();
}
}