如题所述
第1个回答 2011-05-20
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
char alpha[26]={'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'}; //
int count[26]={0};
int i;
char s[100];
cin>>s;
for(i=0;i<strlen(s);++i){
for(int j=0;j<26;++j)
if(s[i]==alpha[j]){
++count[j];
break;
}
}
for(i=0;i<26;++i)
cout<<alpha[i]<<" "<<count[i]<<endl;
}本回答被网友采纳
#include<cstring>
using namespace std;
int main()
{
char alpha[26]={'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'}; //
int count[26]={0};
int i;
char s[100];
cin>>s;
for(i=0;i<strlen(s);++i){
for(int j=0;j<26;++j)
if(s[i]==alpha[j]){
++count[j];
break;
}
}
for(i=0;i<26;++i)
cout<<alpha[i]<<" "<<count[i]<<endl;
}本回答被网友采纳
第2个回答 2017-08-01
用数组去做:
void main()
{
char a[100];
int num,j;
char i;
printf("shuzifuchuan:");
scanf("%s",a);
for(i='A';i<='Z';i++)
{
num=0;
for(j=0;a[j]!='\0';j++)
{
if(i==a[j]||i==a[j]-'a'+'A')
num++;
}
printf("%c:%d ",i,num);
}
}