
Contents
Problem
題目網址
給你字串,算有幾個是Cool words!
Cool words 也就是字串中有至少兩種字母,每種字母的字數都要不一樣。
Solution
用 int alphabet[26] 記下26個字母的個數,再用 bool num[31] 判斷數字是否有重複即可,記得處理字母種類只有一種的狀況。
Code
UVa 12820UVa 12820 - Cool Word
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
int () { int n, Case = 0;
while (scanf("%d", &n) != EOF) { getchar(); int count = 0; char c;
while (n--) { bool diff = false; int alphabet[26] = {}; int len = 0;
while ((c = getchar()) != 'n') { alphabet[c - 'a']++; len++; }
bool num[31] = {}, isCool = true; for (int i = 0; i < 26; i++) { if (alphabet[i]) { if (num[alphabet[i]] || len == alphabet[i]) { isCool = false; break; } else num[alphabet[i]] = true; } }
if (isCool) count++; }
printf("Case %d: %dn", ++Case, count); }
return 0; }
|
近期评论