Kiku


私信TA

用户名:Kiku

访问量:5718

签 名:

如果是哥哥的话进来也没关系哦

等  级
排  名 3033
经  验 1095
参赛次数 0
文章发表 3
年  龄 0
在职情况 学生
学  校 湖北工业大学
专  业

  自我简介:

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 人评分

  评论区

循环外的cin.get(ch) 可以去掉
2019-04-10 15:24:15 | |
cin.get(ch);是什么意思
2019-03-25 12:38:23 | |
  • «
  • 1
  • »