首页 > 其他 > 详细

1200: 字符串数字字母空格其他字符的个数

时间:2019-01-30 10:39:12      阅读:144      评论:0      收藏:0      [点我收藏+]

题目描述

输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。

输入

一行字符。

输出

分别输出这行字符中的英文字母、空格、数字和其他字符的个数,用空格隔开。
请注意行尾输出换行。

样例输入

What are you doing? 123456

样例输出

15 4 6 1

 1 #include<stdio.h>
 2 #include<string.h>
 3 int main(){
 4     char str[1000];
 5     fgets(str,1000,stdin);
 6     int a=0,b=0,c=0,d=0;
 7     int len=strlen(str);
 8     for(int i=0;i<len-1;i++){
 9         if((str[i]>=A&&str[i]<=Z )||( str[i]>=a&&str[i]<=z)){
10             a++;
11         }else if(str[i]== ){
12             b++;
13         }else if(str[i]>=0&&str[i]<=9){
14             c++;
15         }else{
16             d++;
17         }
18     }
19     printf("%d %d %d %d\n",a,b,c,d);
20     return 0;
21 }

Mist Note:没啥说的,主要是通过这个例子发现fgets函数好像会把换行符读进去。当你在dos窗口按enter,回车也会被收进去。

注意去除换行符。

1200: 字符串数字字母空格其他字符的个数

原文:https://www.cnblogs.com/mist2019/p/10336945.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!