ALGO-470
资源限制
内存限制:256.0MB C/C++时间限制:1.0s Java时间限制:3.0s Python时间限制:5.0s
问题描述
编写一个程序,不断输入字符直到遇到’#’为止。然后输出读入的空格’ ’,换行符’\n’和其它字符个数。(注:最后的‘#’不计入其他字符)
样例输入
Chapter 1. Getting Ready
Chapter 2. Introducing C
Chapter 3. #
样例输出
8 2 51
分析:让字符一个一个的输入,然后累加空格、换行符和字符出现的次数输出即可。
#include<stdio.h>
int main(){
char ch;
int space=0, n=0, other=0;
for(int i=0; ;i++){
scanf("%c", &ch);
if(ch=='#'){
break;
}else if(ch==' '){
space++;
}else if(ch=='\n'){
n++;
}else{
other++;
}
}
printf("%d %d %d", space, n, other);
return 0;
}