c++実装統計文字列における各文字の個数
1097 ワード
#include<iostream>
#include<string>
using namespace std;
void tongji(char*,int);
int main()
{
char a[100];
cout<<" :";
gets_s(a);
int n=strlen(a);
cout<<" :"<<endl;
cout<<a<<endl;
tongji(a,n);
system("pause");
return 0;
}
void tongji(char s[],int s1)
{
int num=0,str=0,space=0,other=0;
for(int i=0;i<s1;i++)
{
if((s[i]>='a'&&s[i]<='z')||(s[i]>='A'&&s[i]<='Z'))
++str;
else if(s[i]>='0'&&s[i]<='9')
++num;
else if(s[i]==' ')
++space;
else ++other;
}
cout<<" :"<<str<<endl;
cout<<" :"<<num<<endl;
cout<<" :"<<space<<endl;
cout<<" :"<<other<<endl;
}