hpuoj 【1130】字符串统计【字符串】

来源:互联网 发布:碎屏幕手机壁纸软件 编辑:程序博客网 时间:2024/05/24 02:34

1130: 【C语言程序设计】[7.4.5]字符串统计 [字符串]

时间限制: 1 Sec 内存限制: 128 MB

提交: 126 解决: 91 

题目描述

统计字符串中字母、数字、空格和其它字符的个数。

输入

一个长度不超过100,包含大写字母、小写字母、数字、空格和其它英文字符的字符串。

输出

分别输出字母、数字、空格和其它英文字符的个数。

样例输入

I love ACM 233!

样例输出

8 3 3 1解析:    字符串的输入以及判断字符的类型。程序如下:
#include<cstdio>#include<cstring>int main(){char c[103];gets(c);int l,i;int word=0,number=0,blank=0,other=0;l=strlen(c);for(i=0;i<l;i++){if(c[i]>=97&&c[i]<=122||c[i]>=65&&c[i]<=100)    word++;else if(c[i]>='0'&&c[i]<='9')   number++;else if(c[i]==' ')   blank++;else   other++;}printf("%d %d %d %d\n",word,number,blank,other);return 0;}