当前位置:网站首页>字符统计柱状图
字符统计柱状图
2022-08-09 23:46:00 【-JMY-】
题目描述
小明最近玩起了字符游戏,规则是这样的:读入四行字符串,其中的字母都是大写的,小明想打印一个柱状图显示每个大写字母的频率。你能帮助他吗?
输入
共有4行:每行为一串字符,不超过100个字符。
输出
与样例的格式保持严格一致。
样例输入
THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG. THIS IS AN EXAMPLE TO TEST FOR YOUR HISTOGRAM PROGRAM. HELLO!
样例输出
*
*
* *
* * * *
* * * *
* * * * * *
* * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * *
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
参考代码:
#include<bits/stdc++.h>
using namespace std;
string s;
int maxn,t[26];
int main(){
for(int i=0;i<4;i++){
getline(cin,s);
for(int j=0;j<s.size();j++)
if(s[j]>='A'&&s[j]<='Z'){
t[s[j]-'A']++;
maxn=max(maxn,t[s[j]-'A']);
}
}
for(int i=maxn;i>0;i--){
for(int j=0;j<26;j++){
if(t[j]>=i)
printf("* ");
else if(t[j]!=0)
printf(" ");
}
printf("\n");
}
for(int i=0;i<26;i++)
if(t[i]!=0)
printf("%c ",'A'+i);
return 0;
}
边栏推荐
- 【问题解决】训练和验证准确率很高,但测试准确率很低
- Redis-基本介绍/linux下环境配置/配置文件
- 网络协议05 -网络层
- CST Studio Suite 2021 software installation package and installation tutorial
- 天猫全网商品详情封装接口
- 游泳馆系统次卡的设置有哪些细节?
- 最高月薪15K,谁有历经千辛万苦的意志,谁就能收获属于自己的成功~
- Wireshark classic practice and interview 13-point summary
- 深入理解Aarch64内存管理
- 字节技术面都过了,薪资都谈好了20K*13结果还是被刷了,问HR原因是。。。
猜你喜欢
随机推荐
数据的存储——C语言
The technical aspects of the byte have been passed, and the salary has been negotiated for 20K*13, but the result is still being brushed. I asked the HR why...
3.1 - 程序设计语言 3.2 - 高级语言的特点及引用 3.3 - 静态/动态类型语言
MATLB|And her ups and downs and finally reached the peak of life [Romantic Journey]
PEG 衍生物Biotin-PEG1-OH(cas:95611-10-2,2-生物素氨基乙醇)优势说明
网络协议05 -网络层
《MySQL入门很轻松》第4章:数据表中存放的数据类型
温度响应性纳米水凝胶光子品体/纤维素修饰荧光水凝胶/载脂质体水凝胶的制备方法
今日睡眠质量记录61分
断开和服务器共享连接的方法「建议收藏」
ES6 Beginner to Mastery #13: Extension Methods for Arrays 2
Kubernetes服务接入Istio
openEuler 知:abi 检测
Linux安装Oracle和postgrepSQL数据库
第十五章 mysql存储过程与存储函数课后练习
Alibaba Cloud SMS Service Activation
【数据存储】signed,unsigned到底怎么区分?如何计算?
pytest:如何在测试中编写和报告断言
c语言文件基本操作总结
The older tester has just passed the "hurdle" of being 35 years old, and I want to tell you something from my heart









