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 ...
随机推荐
- 【Matplotlib】设置刻度(1)
刻度设置 参考文档: xticks 命令 yticks 命令 以xticks为例: matplotlib.pyplot.xticks(*args, **kwargs) 获取或者设置当前刻度位置和文本的 ...
- You've got to find what you love
你必须找到你爱的东西 You've got to find what you love 史蒂夫乔布斯2005年6月在斯坦福大学毕业典礼上的演讲 I am honored to be with you ...
- HD 2177(威佐夫博弈 入门)
取(2堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 1176 免费馅饼(动态规划)
AC code: #include<stdio.h> #include<string.h> #define max(a,b) (a>b?a:b) #define maxo ...
- mingw32-g++.exe: *: No such file or directory错误解决方法
初次使用CodeBlocks,好不容易把环境配好, 编译没有错误了,但是程序并不生成exe,提示以下问题: mingw32-g++.exe: /W3: No such file or director ...
- IE浏览器模式设置
文件兼容性用于定义让IE如何编译你的网页.此文件解释文件兼容性,如何指定你网站的文件兼容性模式以及如何判断一个网页该使用的文件模式. 前言 为了帮助确保你的网页在所有未来的IE版本都有一致的外观,IE ...
- SVM算法入门
转自:http://blog.csdn.net/yangliuy/article/details/7316496SVM入门(一)至(三)Refresh 按:之前的文章重新汇编一下,修改了一些错误和不当 ...
- web前端socket封装库--giraffe
摘要: 最近在做前端的socket消息推送,使用了socket.io.js的最新版本.使用过的都知道socket.io.js是基于消息类型来通信的,如果消息类型多了就很难维护.所以本人就对socket ...
- C# Web开发打开下载对话框代码
一个按钮的事件中写: string filename = Sever.UrlEncode("词库.txt"); Response.AddHeader("Content-D ...
- ruby实现简易计算器
(这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 回到家里,用的还是windows系统,ruby的编辑器换成了Aptana Studio 3 p ...