#include<iostream>
#include<cstdlib>
//下面这段代码不可少,
using namespace std;
//统计ASCII码出现的次数
void histogram(char* src){
int i;
char hist[256];
for(i=0;i<=255;i++){
hist[i]=0;
//cout<<hist[i];
}
cout<<src;
cout<<endl;
//循环读取字符串中的字符 ,直到字符串结尾
while(*src!='\0'){
hist[*src]++;
//向后移动
*src++;
}
for(i=0;i<=255;i++){
printf("%d ",hist[i]);
}
cout<<endl;
}
//统计a-z和A-Z出现的次数,统计数字出现的次数
void histoaz(char* src){
int i=0;
char hist[26];
int m=0;
for(i=0;i<26;i++){
hist[i]=0;
}
while(*src!='\0'){
if(*src>='a' && *src<='z'){
int n=*src-'a';
hist[n]++;
}else
if(*src>='A' && *src<='Z'){
int n=*src-'A';
hist[n]++;
}else if(*src>='0'&&*src<='9'){
//记录出现数字的次数
m++;
}
*src++;
}
//循环输出字母出现的次数
for(i=0;i<26;i++){
printf("%c %d ",(i+65),hist[i]);
}
cout<<endl;
cout<<m<<endl;
}
int main(){
char *src="dsfasdfs1354532mmnbjhkjoopsdadf2132165489798";
histogram(src);
histoaz(src);
return 0;
}
输出结果::