题目1098:字母统计
2016-04-09 09:23
387 查看
题目描述:
输入一行字符串,计算其中A-Z大写字母出现的次数
输入:
案例可能有多组,每个案例输入为一行字符串。
输出:
对每个案例按A-Z的顺序输出其中大写字母出现的次数。
样例输入:
样例输出:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int maxn=26;
const int maxl=1000;
int t[maxn];
char s[maxl];
int main()
{
while(scanf("%s",s)!=EOF)
{
memset(t,0,sizeof(t));
for(int i=0;i<strlen(s);i++)
if((s[i]>='A')&&(s[i]<='Z'))
t[s[i]-'A']++;
for(int i=0;i<maxn;i++)
printf("%c:%d\n",'A'+i,t[i]);
}
return 0;
}
输入一行字符串,计算其中A-Z大写字母出现的次数
输入:
案例可能有多组,每个案例输入为一行字符串。
输出:
对每个案例按A-Z的顺序输出其中大写字母出现的次数。
样例输入:
DFJEIWFNQLEF0395823048+_+JDLSFJDLSJFKK
样例输出:
A:0 B:0 C:0 D:3 E:2 F:5 G:0 H:0 I:1 J:4 K:2 L:3 M:0 N:1 O:0 P:0 Q:1 R:0 S:2 T:0 U:0 V:0 W:1 X:0 Y:0Z:0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
const int maxn=26;
const int maxl=1000;
int t[maxn];
char s[maxl];
int main()
{
while(scanf("%s",s)!=EOF)
{
memset(t,0,sizeof(t));
for(int i=0;i<strlen(s);i++)
if((s[i]>='A')&&(s[i]<='Z'))
t[s[i]-'A']++;
for(int i=0;i<maxn;i++)
printf("%c:%d\n",'A'+i,t[i]);
}
return 0;
}
相关文章推荐
- 实现顺序表以及顺序表的简单运算
- js unicode 编码解析关于数据转换为中文的两种方法
- 观察者模式
- SQL中N+1问题已经MyBaits中的解决方案
- VMWare Workstation中实现Win7和linux虚拟机之间的文件共享
- lua 表赋值是引用关系
- nyoj 325 zb的生日【0-1背包】
- String
- java路径问题总结
- 一个jQuery事件绑定的问题
- 杨辉三角形
- hdoj 1203 I NEED A OFFER!【0-1背包+逆向思维】
- float类型进行计算精度丢失的问题
- LINUX内核分析第七周——可执行程序的装载
- ssl2334 铲雪车
- 约瑟夫环问题
- Java中resourceBundle和Properties的区别
- bootstrap 下拉菜单精简版
- 创业公司和大公司的差异
- document.frame