零K沁雪


私信TA

用户名:qczl

访问量:74777

签 名:

零K沁雪

等  级
排  名 40
经  验 12034
参赛次数 3
文章发表 35
年  龄 0
在职情况 在职
学  校
专  业

  自我简介:

解题思路:

1、可以使用gets()/scanf()获取待统计的字符。

2、scanf()获取字符的时候应该使用scanf("%[^\n]"),除了回车键全部读入。

注意事项:

参考代码:

#include<stdio.h>
#include<string.h>

void statistics(char *str, int *num_char, int *num_num, int *space_num, int *other_num)
{
	int len=0, i=0;
	len = strlen(str);
	*num_char = 0;
	*num_num = 0;
	*space_num = 0;
	*other_num = 0;
	for(i = 0; i < len; i++)
	{
		if(str[i]>='0' && str[i]<='9')
			*num_num+=1;
		else if( (str[i]>='a' && str[i]<= 'z') || (str[i]>='A' && str[i]<='Z'))
			*num_char+=1;
		else if(str[i]==' ')
			*space_num+=1;
		else
			*other_num+=1;
	}
}

int main()
{
	char Mystring[1024];
	int num_char, num_num, space_num, other_num;
	scanf("%[^\n]", Mystring);
	statistics(Mystring, &num_char, &num_num, &space_num, &other_num);
	printf("%d %d %d %d\n", num_char, num_num, space_num, other_num);
	return 0;
}


 

0.0分

36 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区

#include<stdio.h>
#include<string.h>
#define STR_SIZE 1000
void flash(int* letter,int* number,int* space,int* other,
    char str1[STR_SIZE])
	{
	    fgets(str1,STR_SIZE,stdin);
	    str1[strcspn(str1,"\n")]=0;
    int i;
    for(i=0;i<strlen(str1);i++)
    {
	if(str1[i]<='z'&&str1[i]>='a'||str1[i]<='Z'&&str1[i]>='A')
    {
    	(*letter)+=1;
	}
	else if(str1[i]<='9'&&str1[i]>='0')
	{
		(*number)+=1;
	}
	else if(str1[i]==' ')
	{
		(*space)+=1;
	}
	else
	{
		(*other)+=1;
	}
	}
	printf("%d %d %d %d",*letter,*number,*space,*other);	
		 }	 
int main()
{
	int letter=0,number=0,space=0,other=0;
2024-02-19 11:04:42
#include<stdio.h>
#include<string.h> 
void draw(char a[])
{
	int len=strlen(a);
	int j=0,h=0,b=0,k=0;
	for(int i=0;i<len;i++)
	{
		if( (a[i]>='a' && a[i]<= 'z') || (a[i]>='A' && a[i]<='Z'))
		{
			j++;
		}
		else if(0<=a[i]<=9)
		{
			h++;
		}
			else if(a[i]==' ')
		{
			i++;
		}
			else
		{
			k++;
		}
	}
	printf("%d %d %d %d",j,h,b,k);
}
int main()
{
	char a[200];
	gets(a);
	draw(a);
	return 0;
}
各位大佬哪里错了
2023-04-23 20:51:39
void PrintCount(char buff[])
{
    int NumberOfLetter = 0 ,NumberOfNum = 0 ,NumberOfSpace = 0 ,NumberOfOther = 0;
    int count  = 0;
    while(buff[count] != '\0')
    {
        if(buff[count] >= '0' && buff[count] <= '9')
        {
            NumberOfNum++;
        }
        else if((buff[count] >= 'a' && buff[count] <= 'z')
        || (buff[count] >= 'A' && buff[count] <= 'Z'))
        {
            NumberOfLetter++;
        }
        else if(buff[count] == ' ')
        {
            NumberOfSpace++;
        }
        else
        {
            NumberOfOther++;
        }
        count++;
2022-06-19 16:55:45
#include<stdio.h>
#include<string.h>
void statisticsn(char a[],int l,int *words,int *maths,int *empty,int *other){
	for(int i=0;i<l;i++){
			if(a[i] >= 'A' && a[i] <= 'Z' || a[i] >= 'a' && a[i] <= 'z'){
				(*words)++;
			} else if(a[i] >= '0' && a[i] <= '9'){
				(*maths)++;
			} else if(a[i] == ' ') {
				(*empty)++;
			} else {
				(*other)++;
			}
		}
}
int main(){
	char a[100];
	gets(a);
	int length = strlen(a);
	int words=0,maths=0,empty=0,other=0;
	statisticsn(a,length,&words,&maths,&empty,&other);
	printf("%d %d %d %d",words,maths,empty,other);
	
	return 0;
}
容易理解就完事了~~~
2022-05-11 10:48:17
#include<stdio.h>
#include<string.h>
void fun(char *i,int j,int *a,int *b,int *c,int *d)
{
		*a = 0;
		*b = 0;
		*c = 0;
		*d = 0;
	for(int m = 0;m < j;m++)
	{
		if((i[m] >= 'a' && i[m] <= 'z') || (i[m] >= 'A' && i[m] <= 'Z'))
			*a+=1;
		else if(i[m] >= '0' && i[m] <= '9')
			*b+=1;
		else if(i[m] == ' ')
			*c+=1;
		else 
			*d+=1;
	}
}
int main()
{
	char arr[100];
	int l;
	int a,b,c,d;
	gets(arr);
	l = strlen(arr);
	fun(arr,l,&a,&b,&c,&d);
	printf("%d %d %d %d\n",a,b,c,d);
	return 0;
}
2022-05-06 21:48:40
#include<stdio.h>
#include<string.h>
int main()
{
    int i,j=0,k=0,d=0,s=0,n;
    char a[100];
    for(i=0;i<100;i++){
        scanf("%c",&a[i]);
	}
	n=strlen(a);
	for(i=0;i<n;i++){
        if((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z'))
            j++;
            else
            if(a[i]>='0'&&a[i]<='9')
            k++;
            else
            if(a[i]==' ')
            d++;
            else
            s++;
    }
   printf("%d %d %d %d",j,k,d,s);
    return 0;
}
为什么错误
2022-04-10 15:38:48
#include<stdio.h>
#include<string.h>
extern int q=0,w=0,e=0,r=0;
void x(char a[30])
{
    int i,len;
    len=strlen(a);
    for(i=0;i<len;i++)
    {
        if((a[i]>='A'&&a[i]<='Z')||(a[i]>='a'&&a[i]<='z'))
        q++;
        else if(a[i]>='0'&&a[i]<='9')
        w++;
        else if(a[i]==' ')
        e++;
        else
        r++;
    }
}
int main()
{
    char a[30]={};
    gets(a);
    x(a);
    printf("%d %d %d %d",q,w,e,r);
}
为什么结果正确但运行错误50呢?@.@
2022-01-27 11:30:31
#include"stdio.h"
#include"string.h"
#include"ctype.h"//以便调用函数isalpha(),isdigit(),isblank() 
int tongji(char s[])
{
	int a=0,b=0,c=0,d=0,i,l;
	l=strlen(s);
	for(i=0;i<l;i++)
	{
		if(isalpha(s[i]))//判断是否为字母 
		  a++;
		else if(isdigit(s[i]))//判断是否为数字 
		  b++;
		else if(isblank(s[i]))//判断是否为空格 
		  c++;
		else 
		  d++;
	}
	printf("%d %d %d %d\n",a,b,c,d);
} 
int main()
{
	char s[1000];
	gets(s);//输入字符串 
	tongji(s);
	return 0;
}
2021-12-06 12:59:43