admin 管理员组

文章数量: 1086019


2024年4月22日发(作者:log4j控制台输出)

0903-统计字符个数(指针)

时间限制:

1000 毫秒

内存限制:

32768 K字节

总提次数:

689 次

成功提交次数:

455 次

判题规则:

严格比较

问题描述

输入一行字符,统计并输出其中数字字符、英文字母和其它字符的个数。

要求:

1、编写一函数void count(char *s,int *pdigit,int *pletter,int *pother),其中s为

输入的字符串,*pdigit, *pletter,*pother分别表示字符串中数字、字母和其他字符的个数。

输入

输入1个字符串。

输出

输出数字、字母和其他字符的个数。每个数后有一空格。

输入样列

wenzhou university 1933

输出样例

4 17 2

出处

ymc

答案:

#include

#include

void count(char s[],int *pdight,int *pletter,int *pother)

{

int n;

int i;

n=strlen(s);

for(i=0;i

{

if(s[i]>=65&&s[i]<=122)

(*pletter)++;

else if(s[i]>=48&&s[i]<=57)

(*pdight)++;

else

(*pother)++;

}

}

int main()

{

char s[100];

int dight=0;

int letter=0;

int other=0;

gets(s);

count(s,&dight,&letter,&other);

printf("%d %d %d n",dight,letter,other);

return 0;

}


本文标签: 字符 输出 数字 限制 统计