POJ 2136 Vertical Histogram(当时写的比较恶心,优化一下)
Vertical Histogram
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 21223 Accepted: 10048
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.
OutputLines 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
Source
USACO 2003 February Orange
题意很简单,统计每个字母的个数,但是打印起来比较麻烦,签到题。
#include<iostream>
#include<map>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
char a[100];
char b[100];
char c[100];
char d[100];
int ob[25];
int main()
{
int ans=0;
memset(ob,0,sizeof(ob));
gets(a);
gets(b);
gets(c);
gets(d);
for(int i=0;i<100;i++){
if(a[i]>='A'&&a[i]<='Z') ob[a[i]-'A'+1]++;
if(b[i]>='A'&&b[i]<='Z') ob[b[i]-'A'+1]++;
if(c[i]>='A'&&c[i]<='Z') ob[c[i]-'A'+1]++;
if(d[i]>='A'&&d[i]<='Z') ob[d[i]-'A'+1]++;
}
for(int i=0;i<=26;i++)
ans=max(ob[i],ans);
for(int i=ans;i>=1;i--){
for(int j=1;j<=26;j++)
if(ob[j]>=i)cout<<"* ";
else cout<<" ";
cout<<endl;
}
for(int j=0;j<=25;j++)
{
cout<<char(j+'A')<<' ';
}
}
POJ 2136 Vertical Histogram(当时写的比较恶心,优化一下)的更多相关文章
- Poj 2136 Vertical Histogram(打印垂直直方图)
一.Description Write a program to read four lines of upper case (i.e., all CAPITAL LETTERS) text inpu ...
- poj 2136 Vertical Histogram 解题报告
题目链接:http://poj.org/problem?id=2136 题意不难理解,就是输入四行字符串(每行字符总数不超过72个),统计26个英文字母的数目,并按柱状图的形式输出.我的思路就是,先用 ...
- POJ 2136 Vertical Histogram
题意:按样例那样模拟…… 解法:模拟…… 代码: #include<stdio.h> #include<iostream> #include<algorithm> ...
- J - Vertical Histogram(1.5.7)
J - Vertical Histogram(1.5.7) Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d &am ...
- POJ 3635 - Full Tank? - [最短路变形][手写二叉堆优化Dijkstra][配对堆优化Dijkstra]
题目链接:http://poj.org/problem?id=3635 题意题解等均参考:POJ 3635 - Full Tank? - [最短路变形][优先队列优化Dijkstra]. 一些口胡: ...
- POJ 3013 Big Christmas Tree(最短Dijkstra+优先级队列优化,SPFA)
POJ 3013 Big Christmas Tree(最短路Dijkstra+优先队列优化,SPFA) ACM 题目地址:POJ 3013 题意: 圣诞树是由n个节点和e个边构成的,点编号1-n. ...
- 打表格,字符串处理,POJ(2136)
题目链接:http://poj.org/problem?id=2136 水题WA了半天,结果是数组开小了. #include <stdio.h> #include <string.h ...
- POJ 2136
#include <iostream> #include <string> #define MAXN 26 using namespace std; int _m[MAXN]; ...
- 【POJ2136】Vertical Histogram(简单模拟)
比较简单,按照样例模拟就好!~ #include <iostream> #include <cstdlib> #include <cstdio> #include ...
随机推荐
- 小程序wepy2 模拟vant PasswordInput, NumberKeyboard 密码输入框控件
vant weapp小程序端控件目前是没有PasswordInput,NumberKeyboard的.实现效果: 数字键盘组件代码(keyboard.wpy): <template> &l ...
- 原生js俄罗斯方块
效果图 方块定位原理通过16宫格定位坐标,把坐标存到数组中去 [ [[2,0],[2,1],[2,2],[1,2]],//L [[1,1],[2,1],[2,2],[2,3]], //左L [[2,0 ...
- CORS漏洞的学习与分析
同源策略 同源策略(Same origin policy)是一种约定,一种非常重要的安全措施,也是最基本的安全功能,它禁止了来自不同源的脚本对当前页面的读取或修改,从而限制了跨域访问甚至修改资源,防止 ...
- python初学(一)
1.输入一个百分制成绩,要求输出成绩等级A.B.C.D.E,其中90~100分为A,80~89分为B,70~79分为C,60~69分为D,60分以下为E. 要求:1)用if语句实现:2)输入百分制成绩 ...
- 软件包管理rpm和yum
rpm的使用: 安装的包相关包信息会保存在/var/lib/rpm目录下的文件中 安装参数: -i install安装 -v 显示详细信息 -h 打印####号 -V 校验软件包,会到/var/lib ...
- 第八节:time和random模块
定义: 模块是一组Python代码的集合,可以使用其他模块,也可以被其他模块使用. 重点: 1.模块的名字不要和自带的模块名字相同,不然会优先调用自己的那个模块,因为查找模块的时候是按照sys.pat ...
- stand up meeting 12-14
今日更新: 项目的refactor部分均已经基本完成.答题界面和结果展示界面与code hunters team项目的merge部分也已经完成. 当然在这其中我们也遇到了一个小问题,在背单词模块中的词 ...
- Hugo博客搭建
HUGO + Github + Github Action持续集成部署个人博客 HUGO本地环境 首先在HUGO的官网下载Hugo的Windows安装包,然后将路径添加到环境变量即可. step1:下 ...
- 2.hover的使用
1. 自身的hover div :hover{ :hover前要有空格 } 2.hover指向子元素 father:hover .childer { :hover前不能有空格 } 3.ho ...
- [PHP] 文件创建、写入、读取
创建$p = fopen('text.txt','a+b'); 写入第一种方式//var_export方式存储数组到文件中 //这中方式存浮点型数据,存储后会多很多数字!只适合简单的存储吧!我感觉! ...