A Pangram

来源:互联网 发布:csmar数据库怎么用 编辑:程序博客网 时间:2024/06/06 11:52

Codeforces Round #295 div2 的A题,题意是判读一个字符串是不是全字母句,也就是这个字符串是否包含了26个字母,无论大小写。


Sample test(s)
input
12toosmallword
output
NO
input
35TheQuickBrownFoxJumpsOverTheLazyDog
output
YES
input 的第一行是字符串的长度,第二行是字符串,output的话,如果不是pangram就输出NO,否则输出YES

因为只要判断是否包含26个字母,所以,如果字符串长度小于26的话,根本上是不可能的,然后,遍历字符串的每个字符,把出现的字母记录下来(打表),最后,判断26个字母是否都包含,很简单的一道题。

#include <iostream>#include <ctype.h>#include <string>using namespace std;int alph[27];int main(){    string s;    int n, i;    cin >> n;    cin >> s;    if(n < 26){cout << "NO"; return 0;    }    for( i = 0; i < n; i++){    char c = s[i];    c = tolower(c);    alph[c-97] = 1;    }    for( i = 0; i < 26; i++){    if(!alph[i]) break;    }    if(i == 26) cout << "YES";    else cout << "NO";    return 0;}


0 0
原创粉丝点击