第十五周 OJ 统计字符串种类

来源:互联网 发布:做软装用什么软件 编辑:程序博客网 时间:2024/04/30 06:19

烟台大学 计算机控制与工程学院

作者:单长喜

题目描述:输入一个字符串,输出字符串中大写字母,小写字母,数字,其他字符类型,最后输出总长度。

程序:

#include <stdio.h>int main(){   char str[100];   gets(str);   char *ptr=str;   void fuction(char *);   fuction(ptr);   return 0;}void fuction(char s[100]){    int i=0,a=0,b=0,c=0,d=0;    while(s[i]!='\0')    {        if(s[i]>='A'&&s[i]<='Z')            a++;        else if(s[i]>='a'&&s[i]<='z')             b++;         else if(s[i]>='0'&&s[i]<='9')             c++;         else            d++;         i++;    }    printf("%d\n%d\n%d\n%d\n%d",a,b,c,d,i);}


结果:


1 0
原创粉丝点击