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语言考试练习题_排列 (C语言代码)浏览:750 |
妹子杀手的故事 (C语言代码)浏览:1256 |
C语言训练-数字母 (C语言代码)浏览:665 |
【蟠桃记】 (C语言代码)浏览:677 |
校门外的树 (C语言代码)浏览:723 |
printf基础练习2 (C语言代码)浏览:639 |
矩形面积交 (C++代码)浏览:1175 |
C二级辅导-等差数列 (C语言代码)浏览:775 |
C语言训练-求PI* (C语言代码)浏览:516 |
纪念品分组 (C++代码)浏览:852 |