Vertical Histogram垂直直方图
2015-08-19 16:54
411 查看
E - Vertical Histogram
Crawling in process...
Crawling failed
Time Limit:1000MS
Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
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.
Input
* Lines 1..4: Four lines of upper case text, no more than 72 characters per line.
Output
* 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.
Sample Input
Sample Output
Crawling in process...
Crawling failed
Time Limit:1000MS
Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit
Status
Description
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.
Input
* Lines 1..4: Four lines of upper case text, no more than 72 characters per line.
Output
* 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.
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 AC代码: #include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int maxn=-1; string s; int cnt[30]; memset(cnt,0,sizeof(cnt)); for(int i=0; i<4; i++) { getline(cin,s); for(int j=0; j<s.length(); j++) if(isupper(s[j])) cnt[s[j]-'A']++; } for(int i=0; i<26; i++) if(cnt[i]>maxn) maxn=cnt[i]; for(int i=0; i<maxn; i++) { for(int j=0; j<26; j++) if(cnt[j]>=maxn-i) printf("* "); else printf(" "); puts(""); } for(int i=0; i<26; i++) printf("%c ",'A'+i); puts(""); return 0; } //string s的输入用getline(cin,s),长度为s.length(),并且此时的getline(cin,s)可以用gets(s)代替 //char s的输入用gets(s),长度为strlen(s) 运行结果: 学习心得:这个题挺有趣的
相关文章推荐
- 桌面支持--新收邮件看不到(在search folders新建一个unread mail)
- Android Studio百度地图(二)
- POJ 3126 Prime Path
- HAL层分析——初步了解HAL
- BZOJ 1068 [SCOI2007]压缩
- 【SQL语句】 - 在所有存储过程中查找关键字,关键字不区分大小写 [sp_findproc]
- (easy)LeetCode 263.Ugly Number
- MFC常用控件使用方法
- 我们应当怎样做需求分析
- spring Quartz多个定时任务的配置
- ckeditor批量上传图片(下)
- Maven常用库连接
- 在Xcode中玩转Git
- 第一个iOSAPP上架经历
- 解决Xcode6项目中旧项目不全屏问题
- ViewPager点击每一项设置的监听
- 桌面支持--outlook默认中文语言设置
- 【网络流24题之餐巾计划】xoj 1247
- LightOJ - 1422 Halloween Costumes 区间DP
- 值得推荐的C/C++框架和库