Problem F: 統計出其中英文字母、數字、空格和其他字符的個數
Time Limit: 1 Sec Memory Limit: 128 MB
Description
輸入一行字符,分別統計出其中英文字母、數字、空格和其他字符的個數。
Input
一行字符
Output
統計值
Sample Input
aklsjflj123 sadf918u324 asdf91u32oasdf/.';123
Sample Output
23 16 2 4
HINT
參考答案:
#include<stdio.h>
int main()
{
int str=0,nu=0,space=0,ot=0;
char ch;
while((scanf("%c",&ch))!=EOF)
{
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
{
str++;
}
else if(ch>='0'&&ch<='9')
{
nu++;
}
else if(ch==' ')
{
space++;
}
else
ot++;
}
printf("%d %d %d %d",str,nu,space,ot-1);
return 0;
}
編程軟件及學習視頻下載:點擊打開鏈接