CCF NOI1080 统计字符

来源:互联网 发布:飞翔快递打印软件 编辑:程序博客网 时间:2024/06/05 22:58

问题链接:CCF NOI1080 统计字符




时间限制: 1000 ms  空间限制: 262144 KB

题目描述 

  Johe最近玩起了字符游戏,规则是这样的:读入四行字符串,其中的字母都是大写的,Johe想打印一个柱状图显示每个大写字母的频率。你能帮助他吗?

输入

  输入文件共有4行:每行为一串字符,不超过100个字符。

输出

  与样例的格式保持严格一致。

样例输入

THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.THIS IS AN EXAMPLE TO TEST FOR YOURHISTOGRAM PROGRAM.HELLO!

样例输出

                            *                            *        *                   *        *                   *     *   *        *                   *     *   **       *     *             *     *   **       *     * *     * *   *     * * **       *   * * *     * *   * *   * * * **     * * * * * *     * * * * *   * * * *     * ** * * * * * * * * * * * * * * * * * * * * * * * * *A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

数据范围限制

 

提示

 




问题分析

  这个题来自USACO,直接把之前的代码拿来用就可以了。

程序说明

  参见参考链接。

要点详解

  • 一些程序初看时觉得难,看过了也就不难了



参考链接

POJ2136 Vertical Histogram

POJ NOI0113-04 垂直直方图(PKU2800)



100分通过的C++程序:

/* POJ2136 Vertical Histogram */    #include <iostream>  #include <string>  #include <cstring>  #include <cctype>    using namespace std;    const int MAXN = 26;  int acount[MAXN];    int main()  {      int linecount, max;      string s;        memset(acount, 0, sizeof(acount));        linecount = 0;      while (getline(cin, s)) {          // 统计字母          for(int i=0; i<(int)s.size(); i++)  //            if(isalpha(s[i]))  //                acount[s[i] - 'A']++;              if(isupper(s[i]))                  acount[s[i] - 'A']++;            // 每4行输出一次结果          if(++linecount == 4) {              linecount = 0;                // 计算最大的统计值              max = 0;              for(int i=0; i<MAXN; i++)                  if(acount[i] > max)                      max = acount[i];                // 输出max行              for(int i=max; i>0; i--) {                  for(int j=0; j<MAXN; j++) {                      if(acount[j] >= i)                          cout << "* ";                      else                          cout << "  ";                  }                  cout << endl;              }                for(int i=0; i<MAXN; i++)                  cout << (char)('A' + i) << " ";              cout << endl;          }      }        return 0;  } 






0 0