码迷,mamicode.com
首页 > 其他好文 > 详细

luoguoj 1598 垂直柱状图 模拟

时间:2015-05-20 00:25:57      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

P1598 垂直柱状图

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://www.luogu.org/problem/show?pid=1598

Description

写一个程序从输入文件中去读取四行大写字母(全都是大写的,每行不超过72个字符),然后用柱状图输出每个字符在输入文件中出现的次数。严格地按照输出样例来安排你的输出格式。

Input


四行字符,由大写字母组成,每行不超过72个字符

Output

由若干行组成,前几行由空格和星号组成,最后一行则是由空格和字母组成的。在任何一行末尾不要打印不需要的多余空格。不要打印任何空行。

Sample Input

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

Sample Output

                            *
                            *
        *                   *
        *                   *     *   *
        *                   *     *   *
*       *     *             *     *   *
*       *     * *     * *   *     * * *
*       *   * * *     * *   * *   * * * *
*     * * * * * *     * * * * *   * * * *     * *
* * * * * * * * * * * * * * * * * * * * * * * * * *
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

HINT

 

题意

 

题解:

模拟题

代码:

 

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[20];
//const int inf=0x7fffffff;   //нчоч╢С
const int inf=0x3f3f3f3f;
/*

inline void P(int x)
{
    Num=0;if(!x){putchar(‘0‘);puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
*/
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}
    while(ch>=0&&ch<=9){x=x*10+ch-0;ch=getchar();}
    return x*f;
}
inline void P(int x)
{
    Num=0;if(!x){putchar(0);puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
//**************************************************************************************


int a[30];
int main()
{
    string s;
    int ma=0;
    while(cin>>s)
    {

        for(int j=0;j<s.size();j++)
        {
            if(s[j]>=A&&s[j]<=Z){
            a[s[j]-A]++;
            ma=max(a[s[j]-A],ma);
            }
        }

    }
    for(int i=ma-1;i>=0;i--)
    {
        for(int j=0;j<26;j++)
        {
            if(a[j]<=i)
                printf(" ");
            else
                printf("*");
            if(j!=25)
                printf(" ");
        }
        printf("\n");
    }
    char k=A;
    for(int i=0;i<26;i++)
    {
        printf("%c",k+i);
        if(i!=25)
            printf(" ");        
    }
}

 

luoguoj 1598 垂直柱状图 模拟

标签:

原文地址:http://www.cnblogs.com/qscqesze/p/4515970.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!