實機體驗,再天天抽M86檔好股票放一年賺5成輕忽小中風,當心變殘障24天後重啟院會 兩岸...
2012-05-03 17:04:58 人氣(223) | 回應(0) | 推薦(0) | 收藏(0) 上一篇 | 下一篇

[UVA][EASY] 11577 - Letter Frequency

0
收藏
0
推薦

Problem A: Letter Frequency

A weird keyboard

In this problem we are interested in the frequency of letters in a given line of text. Specifically, we want to know the most frequently occurring letter(s) in the text, ignoring case (to be clear, "letters" refers precisely to the 26 letters of the alphabet).

Input begins with the number of test cases on its own line. Each test case consists of a single line of text. The line may contain non-letter characters, but is guaranteed to contain at least one letter and less than 200 characters in total.

For each test case, output a line containing the most frequently occurring letter(s) from the text in lowercase (if there are ties, output all such letters in alphabetical order).

Sample input

1
Computers account for only 5% of the country's commercial electricity consumption.

Sample output

co


#include <stdio.h>

int main() {
int t;
char str[999];
scanf("%d", &t);
getchar();
while(t--) {
gets(str);
int cnt[26] = {}, i;
for(i = 0; str[i]; i++) {
if(str[i] >= 'a' && str[i] <= 'z')
cnt[str[i]-'a']++;
if(str[i] >= 'A' && str[i] <= 'Z')
cnt[str[i]-'A']++;
}
int max = 0;
for(i = 0; i < 26; i++)
max = max > cnt[i] ? max : cnt[i];
for(i = 0; i < 26; i++)
if(cnt[i] == max)
printf("%c", i+'a');
puts("");
}
return 0;
}

11577Letter Frequency
台長:Morris
人氣(223) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][EASY] 445 - Marvelous Mazes
此分類上一篇:[UVA][SSSP] 10986 - Sending email

我要回應
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入以下數字 (ex:123)

(有*為必填)
詳全文