您的位置:首页 > 其它

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

2016-12-13 11:55 281 查看
问题及代码:


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

4
12
1
6
23

/*烟台大学计算机学院
作者:景怡乐
完成时间: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);
}


运行结果:



知识点总结:注意指针变量前面的*
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: