您的位置:首页 > 其它

第十五周oj训练——统计字符串种类(2569)

2016-12-10 20:37 176 查看
问题及代码

Description

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

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

Input

一串字符串

Output

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

Sample Input

I play LOL for 3 years.

Sample Output

4
12
1
6
23

/*烟台大学计算机学院 2016
作者: 马春澎
完成日期:2016年12月10日 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char str[100];
gets(str);
char *ptr=str;
void fuction(char *);
fuction(ptr);
return 0;
}
void fuction(char *p)
{
int i,n,a,b,c,d;
a=b=c=d=0;
n=strlen(p);
for(i=0; i<n; i++)

{
if((p[i]>='A')&&(p[i]<='Z'))
a++;
if((p[i]>='a')&&(p[i]<='z'))
b++;
if((p[i]>='0')&&(p[i]<='9'))
c++;
}
d=n-a-b-c;
printf("%d\n%d\n%d\n%d\n%d",a,b,c,d,n);
}

运算结果


知识点总结

字符串和函数的应用

学习心得

练得多了就会有很大的进步!


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: