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 ...
随机推荐
- MTK Android ListPreference的用法
首先,我们明确,preference是和数据存储相关的. 其次,它能帮助我们方便的进行数据存储!为什么这个地方一定要强调下方便的这个词呢?原因是,我们可以根本就不使用,我们有另外的N种办法可以实现同样 ...
- javascript中的constructor
constructor,构造函数,对这个名字,我们都不陌生,constructor始终指向创建当前对象的构造函数. 这里有一点需要注意的是,每个函数都有一个prototype属性,这个prototyp ...
- 汇编刷题:在M单元和N单元分别存有一个8位无符号数36H和95H,要求比较并输出 M大于N 或者 M小于N
DATA SEGMENT M DB 36H N DB 95H RESAULT1 DB 'M>N$' RESAULT2 DB 'M<N$' DATA ENDS ...
- gcc/g++堆栈保护技术
最近学习内存分布,通过gdb调试发现一些问题,栈空间变量地址应该是从高往低分布的,但是调试发现地址虽然是从高往低分布,但是变量地址的顺序是乱的,请教同事他说可能是gcc/g++默认启用了堆栈保护, ...
- coding++:jdk1.7 HashMap 的get()和put() 源码
HashMap的概述: 基于哈希表的 Map 接口的实现. 此实现提供所有可选的映射操作,并允许使用 null 值和 null 键. (除了非同步和允许使用 null 之外,HashMap ...
- mysql 向上取整
SELECT CEILING(10.0) --->10 SELECT CEILING(10.1) --->11
- CVPR2020|3D-VID:基于LiDar Video信息的3D目标检测框架
作者:蒋天园 Date:2020-04-18 来源:3D-VID:基于LiDar Video信息的3D目标检测框架|CVPR2020 Brief paper地址:https://arxiv.org/p ...
- 【翻译】创建String 使用“”还是构造函数(new String)
在java中创建String,通常有以下两种方法. String x = "abc"; String y = new String("abc"); 它们之间有什 ...
- 程序员小张的第一篇博文 --记Markdown的使用学习
1.前言 为了即将到来的面试做准备,以及记录一下平日里自己的学习过程和生活日常,我开始进驻博客园啦!这就是我的第一篇博客(有点小激动)~ 作为一只新手,首先记录一下今晚的编写博文的学习过程吧~ 2.使 ...
- 基于RabbitMQ的Rpc框架
参考文档:https://www.cnblogs.com/ericli-ericli/p/5917018.html 参考文档:RabbitMQ 实现RPC MQ的使用场景大概包括解耦,提高峰值处理能力 ...