2010年7月29日 星期四

499 - What's The Frequency, Kenneth

#include <stdio.h>

main()
{
int i;
char *suffix[]= { "st", "nd", "rd" };
char *item[]= { "Unix" , "cat", "sed", "awk", "grep", "ed", "vi"};

printf("In the beginning, there was nothing.\n");
for (i= 0; i < 7; i++)
printf("And on the %d%s day, God created %s. And it was good.\n",
i + 1, (i < 3) ? suffix[i] : "th", item[i]);
}
神創造了好用的Unix工具之後,祂發現vi會使人禁不起誘惑而墮落,因為vi功能強大,讓人不願意使用make, dbx, RCS等完善的工具,反而用了命令列來編譯、printf()來除錯、磁帶備份來當版本控管的手段。
所以上帝下了命令:因為工程師們褻瀆了我所創造的vi,所以我決定創造emacs,這是一個功能強大到無法言喻的文字編輯器,至此,工程師們只要用過一次vi,就必須為此飽受磨難,注意!磨難必定是痛苦的,一路上將會荊棘遍佈哀鴻遍野,工程師必須讀取很多列文字,並告訴我每一列中出現頻率最高的字母為何,及它總出現幾次。
我命令你們遵守我訂下的鐵則:“不要讓你的朋友使用vi”

Input and Output

輸出的每一列要包含一列輸入中出現頻率最高的所有字母,並顯示出現多少次。

輸出的字母必須按照字母順序來排序,並且所有大寫字母必須擺在小寫字母之前。

Sample Input

When riding your bicycle backwards down a one-way street, if the
wheel falls of a canoe, how many ball bearings does it take to fill
up a water buffalo?
Hello Howard.

Sample Output

e 6
al 7
a 3
Hlo 2

Hint:
ACM的輸入資料似乎在最後一列有一個換行符號,所以必須避免因些多輸出一空白行的資料。
原文出處

沒有留言:

張貼留言