04:垂直直方图

来源:互联网 发布:你快乐所以我快乐 知乎 编辑:程序博客网 时间:2024/05/22 04:25

04:垂直直方图


总时间限制: 
1000ms 
内存限制: 
65536kB
描述

输入4行全部由大写字母组成的文本,输出一个垂直直方图,给出每个字符出现的次数。注意:只用输出字符的出现次数,不用输出空白字符,数字或者标点符号的输出次数。

输入
输入包括4行由大写字母组成的文本,每行上字符的数目不超过80个。
输出
输出包括若干行。其中最后一行给出26个大写英文字母,这些字母之间用一个空格隔开。前面的几行包括空格和星号,每个字母出现几次,就在这个字母的上方输出一个星号。注意:输出的第一行不能是空行。
样例输入
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 2003 February Orange的试题。

#include <stdio.h>#include <iostream>#include <stack>#include <string.h>#include <queue>#include <cmath>#include <vector>#include <algorithm>#include <map>#include <set>#include <string>#include <iomanip>using namespace std;typedef long long LL;#define MAX 1001int a[MAX][MAX];int b[MAX][MAX];int res[MAX][MAX];int t[26];int main() {    //freopen("in.txt", "r", stdin);    //freopen("out.txt", "w", stdout);    string temp, str = "";    while(getline(cin, temp)){        str += temp;    }    int max = 0;    for(int i = 0; i < str.size(); i++){        if(str[i] >= 'A' && str[i] <= 'Z'){            t[str[i] - 'A'] ++;            if(t[str[i] - 'A'] > max){                max = t[str[i] - 'A'];            }        }    }    for(int i = max; i >= 1; i--){        for(int j = 0; j < 26; j++){            if(t[j] < i){                cout << ' ' << " ";            }else {                cout << '*' << " ";            }        }        cout << endl;    }    for(int i = 0; i < 26; i++){        cout << (char)('A' + i) << " ";    }    //cout << str << endl;    return 0;}



原创粉丝点击