poj 2136 Vertical Histogram 解题报告
题目链接:http://poj.org/problem?id=2136
题意不难理解,就是输入四行字符串(每行字符总数不超过72个),统计26个英文字母的数目,并按柱状图的形式输出。我的思路就是,先用一维数组total[]统计每个英文字母的个数,接着找出最大的频率,保存在max中;紧接着用一个二维数组word[][](这个比较关键)记录每一个字母在0~max中是否存储数据,有的话则置1,没有则为0。(假如:字母'A'的频率是2,max = 10,那么word[0][0] = 0, word[0][1] = 1, word[0][2] = 1, word[0][3] = 0......word[0][10] = 0,代表)接着用两重循环输出表格即可。
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std; const int maxn = ; int main()
{
char s[];
int i, j, n, len, max, total[maxn], word[maxn][];
n = ;
memset(total, , sizeof(total));
while (n--)
{
gets(s);
len = strlen(s);
for (i = ; i < len; i++)
{
total[s[i]-'A']++; // 统计每个字母出现的次数(total[0]对应'A',total[1]对应'B',依此类推)
}
}
max = total[];
for (i = ; i <= ; i++)
{
if (max < total[i]) // 在所有字母中找出最大的出现次数
max = total[i];
}
memset(word, , sizeof(word));
for (i = ; i <= ; i++)
{
for (j = ; j <= total[i]; j++)
{
word[i][j] = ; // 标记每个字母出现的数目
}
}
for (i = max; i > ; i--)
{
for (j = ; j <= ; j++)
{
if (!word[j][i] && j == )
{
printf(" ");
}
else if (word[j][i] && j == )
printf("*");
else if (!word[j][i])
printf(" ");
else if (word[j][i])
printf(" *");
}
printf("\n");
}
for (i = ; i <= ; i++)
{
if (i == )
printf("%c", i + 'A');
else
printf(" %c", i + 'A');
}
printf("\n");
return ;
}
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(当时写的比较恶心,优化一下)
Vertical Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21223 Accepted: 10048 ...
- POJ 2136 Vertical Histogram
题意:按样例那样模拟…… 解法:模拟…… 代码: #include<stdio.h> #include<iostream> #include<algorithm> ...
- Tarjan算法求解桥和边双连通分量(附POJ 3352 Road Construction解题报告)
http://blog.csdn.net/geniusluzh/article/details/6619575 在说Tarjan算法解决桥和边双连通分量问题之前我们先来回顾一下Tarjan算法是如何 ...
- POJ 3126 Prime Path 解题报告(BFS & 双向BFS)
题目大意:给定一个4位素数,一个目标4位素数.每次变换一位,保证变换后依然是素数,求变换到目标素数的最小步数. 解题报告:直接用最短路. 枚举1000-10000所有素数,如果素数A交换一位可以得到素 ...
- 【原创】poj ----- 2376 Cleaning Shifts 解题报告
题目地址: http://poj.org/problem?id=2376 题目内容: Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K ...
- 【原创】poj ----- 1611 The Suspects 解题报告
题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS Memory Limit: 20000K To ...
- 【原创】poj ----- 2524 Ubiquitous Religions 解题报告
题目地址: http://poj.org/problem?id=2524 题目内容: Ubiquitous Religions Time Limit: 5000MS Memory Limit: 6 ...
- [POJ 1002] 487-3279 C++解题报告
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 228365 Accepted: 39826 D ...
随机推荐
- JSP页面中 <base href="<%=basePath%>">
base标记是一个基链接标记,是一个单标记.用以改变文件中所有连结标记的参数内定值.它只能应用于标记<head>与</head>之间.你网页上的所有相对路径在链接时都将在前面加 ...
- Jfreechart 乱码
整个图标分成三部分chart title,chart 的plot还有chart的 legend三个部分需要对他们分别设置字体就对了. 先看解决方法( 把这几个全部设置了,都搞定了就可以了): ...
- ASP.NET MVC 中将数据从View传递到控制器中的三种方法(表单数据绑定)
http://www.cnblogs.com/zyqgold/archive/2010/11/22/1884779.html 在ASP.NET MVC框架中,将视图中的数据传递到控制器中,主要通过发送 ...
- MySQL------如何安装mysql-connector-java-5.1.38.zip
下载地址:http://dev.mysql.com/downloads/connector/j/ 安装mysql-connector-java-5.1.38.zip:1.解压文件->把里面的my ...
- stl-基本知识
摘要:本文列出几个基本的STL map和STL set的问题,通过解答这些问题讲解了STL关联容器内部的数据结构,最后提出了关于UNIX/LINUX自带平衡二叉树库函数和map, set选择问题,并分 ...
- 调用MySql 分页存储过程带有输入输出参数
Create PROCEDURE getuser ( IN pageIndex INT, IN pageSize INT, OUT count INT ) BEGIN )*pageSize; sele ...
- Swig 使用指南
如何使用 API swig.init({ allowErrors: false, autoescape: true, cache: true, encoding: 'utf8', filters: { ...
- 简论:int i = 0
int i =0; 或许这就是i和0的缘分吧...
- 解决android:theme="@android:style/Theme.NoDisplay" 加入这句话后程序不能运行
原因: 原来用的是ActionBarActivity,继承自 ActionBarActivity的类必须指定固定的集中Theme风格,而这些 Theme 风格是需要导入V7中的 appcompat L ...
- The Perfect Stall (incomplete)
恩,一看就知道是一道二分图最大匹配的题. 感动得发现自己不会做..果然我是太弱了.学校里真是麻烦死,根本没有时间好吗. (NOIP)会不会感动地滚粗啊? 然后稍微看看,恩,匈牙利算法. 真是感动得落泪 ...