本文主要是介绍POJ 2136 Vertical Histogram,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
分析:很久以前,在《K&R》上面碰到过这个题,只不过比这个复杂一点。。。。
也是水题,没什么说的,注意一下细节,比如输出的格式等,还有就是,一开始用的for循环,每输入一行结束后就直接打印,好郁闷^~_~^
Description
Input
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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>using namespace std;int main()
{int len,i,j,maxhigh=0;string s;int c[26];memset(c,0,sizeof(c));while (cin>>s){len=s.length();for(i=0;i<len;i++)if(s[i]>=65 && s[i]<=90)++c[s[i]-'A'];}for(i=0;i<26;i++)if(maxhigh<c[i])maxhigh=c[i];for(i=maxhigh;i>0;i--){for(j=0;j<26;j++)if(c[j]>=i)printf("* ");elseprintf(" ");printf("\n");}for(i=0;i<26;i++){if(i>0)printf(" ");printf("%c",i+'A');}printf("\n");return 0;
}
Description
Input
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
这篇关于POJ 2136 Vertical Histogram的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!