输入字符串以及输出
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 188 Solved: 116
[ Submit][ Status][ Web Board]
Description
编写一函数,由实参传来一个字符串,统计此字符串中字母、数字、空格和其它字符的个数,在主函数中输入字符串以及输出上述结果。 只要结果,别输出什么提示信息。
Input
一行字符串
Output
统计数据,4个数字,空格分开。
Sample Input
!@#$%^QWERT 1234567
Sample Output
5 7 4 6
#include<iostream>
using namespace std;
void tongji(char str[100],int a[4])
{a[3]=a[2]=a[1]=a[0]=0;
for(int i=0;i<100;i++)
{if(str[i]=='\0')
break;
if(str[i]>='A'&&str[i]<='Z'||str[i]>='a'&&str[i]<='z')
a[0]++;
else if(str[i]>='0'&&str[i]<='9')
a[1]++;
else if(str[i]==' ')
a[2]++;
else
a[3]++;
}
}
int main()
{
char str[100];
int i,a[4];
cin.getline(str,99);
tongji(str,a);
for(i=0; i<4; i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;
}