TZOJ:1584: Vertical Histogram

 非常要注意输出格式!!!

描述

Write a program to read four lines of upper case (i.e., all CAPITAL LETTERS) text input (no more than 72 characters per line) from the input file and print a vertical histogram that shows how many times each letter (but not blanks, digits, or punctuation) appears in the all-upper-case input. Format your output exactly as shown.

输入

Lines 1..4: Four lines of upper case text, no more than 72 characters per line.

输出

* Lines 1..?: Several lines with asterisks and spaces followed by one line with the upper-case alphabet separated by spaces. Do not print unneeded blanks at the end of any line. Do not print any leading blank lines.

样例输入

THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
THIS IS AN EXAMPLE TO TEST FOR YOUR
HISTOGRAM 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

#include <stdio.h>

int main()
{
	char str1[72]={'0'};
	char str2[72]={'0'};
	char str3[72]={'0'};
	char str4[72]={'0'};
	int zd[26]={0};
	gets(str1);
	gets(str2);
	gets(str3);
	gets(str4);	
	int i;
	//printf("%d",(int)(str1[0])-64);
	for(i=0;i<288;i++)
	{
		if(i<72 && str1[i]>='A' && str1[i]<='Z')
			zd[(int)(str1[i])-65]+=1;
		else if(i>=72 && i<144 && str2[i-72]>='A' && str2[i-72]<='Z')
			zd[(int)(str2[i-72])-65]+=1;
		else if(i>=144 && i<216 && str3[i-144]>='A' && str3[i-144]<='Z')
			zd[(int)(str3[i-144])-65]+=1;
		else if(i>=216 && str4[i-216]>='A' && str4[i-216]<='Z')
			zd[(int)(str4[i-216])-65]+=1;
	}
	
	/*for(i=0;i<26;i++)
	{
		printf("%d\n",zd[i]);
	}*/

	int max=0;
	for(i=0;i<26;i++)
	{
		if(zd[i]>max)
		{
			max=zd[i];
		}
	}
	int j,p=0,k;
	for(i=max;i>0;i--)
	{
		for(j=0;j<26;j++)
		{
			if(zd[j]>=i)
			{
				p=j+1;
			}
		}
		for(k=0;k<p;k++)
		{
			if(zd[k]>=i && k!=p-1)
			{
				printf("* ");
			}
			else if(zd[k]<i)
			{
				printf("  ");
			}
			else if(k==p-1 && zd[k]>=i)
			{
				printf("*");
			}
		}

		printf("\n");
	}
	printf("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");
    return 0;
    
    
}
  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值