Description
输入一行文字,找出大写字母,小写字母,空格,数字以及其他字符的数量
Input
SYSU hello 123 ???
Output
uppercase:4
lowercase:5
number:3
blank:3
others:3
Sample Input
SYSU hello 123 ???
Sample Output
uppercase:4 lowercase:5 number:3 blank:3 others:3
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char a[101];
int main()
{
gets(a);
int n=strlen(a);
int f=0;
int b=0;
int c=0;
int d=0;
int e=0;
for(int i=0;i<n;i++)
{
if((a[i]<='Z')&&(a[i]>='A')) f++;
if((a[i]<='z')&&(a[i]>='a')) b++;
if(a[i]==' ') c++;
if((a[i]>='0')&&(a[i]<='9')) d++;
else continue;
}
e=n-f-b-c-d;
cout<<"uppercase:"<<f<<endl;
cout<<"lowercase:"<<b<<endl;
cout<<"number:"<<c<<endl;
cout<<"blank:"<<d<<endl;
cout<<"others:"<<e;
return 0;
}