c实现
#include <stdio.h>
int main()
{
char ch;
int count_of_letter=0;
int count_of_number=0;
int count_of_space=0;
int count_of_other=0;
while(scanf("%c",&ch)&&ch!='\n')
{
if(ch== ' ')
count_of_space++;
else if(ch<='9'&&ch>='0')
count_of_number++;
else if((ch<='z'&&ch>='a')||(ch<='Z'&&ch>='A'))
count_of_letter++;
else
count_of_other++;
}
printf("%d %d %d %d\n",count_of_letter,
count_of_number,count_of_space,count_of_other);
return 0;
}
c++实现
#include <iostream>
using namespace std;
int main()
{
char ch;
int count_of_letter=0;
int count_of_number=0;
int count_of_space=0;
int count_of_other=0;
cin.get(ch);
while(ch!='\n')
{
if(ch== ' ')
count_of_space++;
else if(ch<='9'&&ch>='0')
count_of_number++;
else if((ch<='z'&&ch>='a')||(ch<='Z'&&ch>='A'))
count_of_letter++;
else
count_of_other++;
cin.get(ch);
}
cout<<count_of_letter<<" "
<<count_of_number<<" "
<<count_of_space<<" "
<<count_of_other<<endl;
return 0;
}
0.0分
5 人评分
【绝对值排序】 (C语言代码)浏览:688 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:581 |
最长单词 (C语言代码)浏览:1291 |
【简单计算】 (C语言代码)浏览:613 |
WU-小九九 (C++代码)浏览:1657 |
P1000 (C语言代码)浏览:837 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:443 |
A+B for Input-Output Practice (VI) (C语言代码)浏览:545 |
循环入门练习6 (C语言代码)浏览:804 |
printf基础练习2 (C语言代码)浏览:483 |