Codeforces Round #295 (Div. 2) A. Pangram

http://codeforces.com/problemset/problem/520/A

题意:如果一个字符串26个字母都出现过,则输出YES,否则NO.

PS:A 65,a 97,所以如果输入的是大写字母,-97后为负数,索引非法,所以再-65即可。

代码:

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
#include <bits/stdc++.h>
using namespace std;

int cnt[50] = {0};

int main() {
int n;
string s;
cin >> n >> s;
for (int i = 0; i < n; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
cnt[s[i] - 'a']++;
} else {
cnt[s[i] - 'A']++;
}
}
for (int i = 0; i < 26; i++) {
if (cnt[i] == 0) {
puts("NO\n");
return 0;
// 必须退出程序,不然会一直输出NO。break也不行,会执行下面一句。
}
}
puts("YES\n");
return 0;
};