Saturday, 20 June 2015

Code Forces 520A C++ Solution.

/*
   A. Pangram
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output
Output "YES", if the string is a pangram and "NO" otherwise.
Sample test(s)
input
12
toosmallword
output
NO
input
35
TheQuickBrownFoxJumpsOverTheLazyDog
output
YES
*/



#include<bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/

int main(){

    string str,str2;
    int n,ar[27] = {0};
    char c;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> c;
        str.push_back(c);
    }
    transform(str.begin(), str.end(), str.begin(), ::tolower);

    for(int i = 0; i < str.size();i++){
        if(str[i] == 'a')ar['a'-'a']++;
        else if(str[i] == 'b')ar['b'-'a']++;
        else if(str[i] == 'c')ar['c'-'a']++;
        else if(str[i] == 'd')ar['d'-'a']++;
        else if(str[i] == 'e')ar['e'-'a']++;
        else if(str[i] == 'f')ar['f'-'a']++;
        else if(str[i] == 'g')ar['g'-'a']++;
        else if(str[i] == 'h')ar['h'-'a']++;
        else if(str[i] == 'i')ar['i'-'a']++;
        else if(str[i] == 'j')ar['j'-'a']++;
        else if(str[i] == 'k')ar['k'-'a']++;
        else if(str[i] == 'l')ar['l'-'a']++;
        else if(str[i] == 'm')ar['m'-'a']++;
        else if(str[i] == 'n')ar['n'-'a']++;
        else if(str[i] == 'o')ar['o'-'a']++;
        else if(str[i] == 'p')ar['p'-'a']++;
        else if(str[i] == 'q')ar['q'-'a']++;
        else if(str[i] == 'r')ar['r'-'a']++;
        else if(str[i] == 's')ar['s'-'a']++;
        else if(str[i] == 't')ar['t'-'a']++;
        else if(str[i] == 'u')ar['u'-'a']++;
        else if(str[i] == 'v')ar['v'-'a']++;
        else if(str[i] == 'w')ar['w'-'a']++;
        else if(str[i] == 'x')ar['x'-'a']++;
        else if(str[i] == 'y')ar['y'-'a']++;
        else if(str[i] == 'z')ar['z'-'a']++;
    }
    bool ok = false;
    for(int i = 0; i < 26; i++){
        if(ar[i] >= 1)ok = true;
        else {
            ok = false;
            break;
        }
    }
    if(ok)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

No comments:

Post a Comment