UVA499 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]);
}
    But then God saw that vi led people into temptation. Instead of choosing the righteous ways of make, dbx, and RCS, people used long command lines, printf(), and tape backups.
    So God decreed, “I see that Engineers have thus defiled my vi. And so, I shall create emacs, an editor more powerful than words. Further, for each instantiation vi hitherto, the Engineer responsible shalt perform Penance. And lo, the Penance wilt be painful; there will be much wailing and gnushingof teeth. The Engineer will read many lines of text. For each line of text, the Engineer must tell me which letters occur the most frequently.”
    “I charge you all with My Golden Rule: ’Friends shalt not let friends use vi’.”
Input
The input file consists of a lot of lines of text.
Output
A line of output should contain a list of letters that all occured with the highest frequency in the corresponding input line, followed by the frequency.
    The list of letters should be an alphabetical list of upper case letters followed by an alphabetical list of lower case letters.
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

问题链接UVA499 What’s The Frequency, Kenneth?
问题简述:(略)
问题分析
    这是一个文本处理问题,先按照计数排序原理对字符出现的次数进行统计,然后求一下最大次数,再用最大次数找出出现次数最多的所有字符,并且输出结果。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA499 What's The Frequency, Kenneth? */

#include <bits/stdc++.h>

using namespace std;

const int N = 128;
int cnt[N];

int main()
{
    string s;
    while(getline(cin, s)) {
        memset(cnt, 0, sizeof(cnt));
        for(int i = 0; s[i]; i++)
            cnt[(int)s[i]]++;

        int maxc = 0;
        for(int i = 'A'; i <= 'z'; i++)
            if(cnt[i] > maxc)
                maxc = cnt[i];

        for(int i = 'A'; i <= 'z'; i++)
            if(cnt[i] == maxc)
                cout << (char)i;
        cout << " " << maxc << endl;
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值