Codeforces Round #295 div2 的A题,题意是判读一个字符串是不是全字母句,也就是这个字符串是否包含了26个字母,无论大小写。
Sample test(s)
input
12 toosmallword
output
NO
input
35 TheQuickBrownFoxJumpsOverTheLazyDog
output
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;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。