第15周OJ实践9 统计字符串种类

来源:互联网 发布:什么是淘宝爆款 编辑:程序博客网 时间:2024/05/15 02:56

问题及代码:

Problem I: 统计字符串种类

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 756  Solved: 407
[Submit][Status][Web Board]

Description

用指针编写一个程序,输入字符串后,统计其中各种字符的个数,输出其中大小写字母,数字,以及其他字符的个数。

主函数已经给出,请编写统计字符种类函数。

Input

一串字符串

Output

该字符串中大小写字母,数字,以及其他字符的个数,最后输出总字符串长度。

Sample Input

I play LOL for 3 years.

Sample Output

4121623
/*烟台大学计算机学院作者:景怡乐完成时间:2016年12月10日*/#include <stdio.h>int main(){    char str[100];    gets(str);    char *ptr=str;    void fuction(char *);    fuction(ptr);    return 0;}void fuction(char *ptr){    int a=0,b=0,c=0,d=0,n=0;    while(*ptr!='\0')    {        if(*ptr>='A'&&*ptr<='Z')       //是大写字母的条件            a++;        else if(*ptr>='a'&&*ptr<='z')      //是小写字母            b++;        else if(*ptr>='0'&&*ptr<='9')     //是数字            c++;        else      //其它            d++;        ptr++;    }    n=a+b+c+d;//长度    printf("%d\n",a);    printf("%d\n",b);    printf("%d\n",c);    printf("%d\n",d);    printf("%d\n",n);}

运行结果:


知识点总结:注意指针变量前面的*

0 0