• 习题3-3 数数字 UVa1225


    • 出现了RE(runtime error)原因是maxn给小了
    • 没看清题目,是说1-n中数0-9的出现次数,并不是用户自己输入
    • memset(s(char类型数组),0,sizeof(s))..再用strcat能实现添加元素的作用。
    • 最后注意输出格式==>first
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    #include <stdlib.h>
    
    #define maxn 100000
    char s[maxn];
    int count[10];
    char tmp[5];
    int main()
    {
    	
    	int T;
    	int len;
    	int i;
    	int n;
    	scanf("%d",&T);
    	while(T--)
    	{
    		scanf("%d",&n);
    		memset(s,0,sizeof(s));
    		memset(count,0,sizeof(int)*10);
    		for(i=1;i<=n;i++)
    		{
    			sprintf(tmp,"%d",i);
    			strcat(s,tmp);
    		}
    		len= strlen(s);
    		for(i = 0;i<len;i++) count[s[i]-'0']++;
    		int j;
    		int first=1;
    		for(j=0;j<10;j++) 
    			if(first) 
    				{printf("%d",count[j]);
    				first=0;} 
    			else  printf(" %d",count[j] );
    		printf("
    ");
    	}
    	return 0;
    }
    
  • 相关阅读:
    c++作业2 9.22
    c++作业1 9.22
    c++练习题2
    c++练习题1
    10.10作业3
    10.10作业2
    10.10作业 1
    9.22作业5
    9.22作业4
    9.22zuo
  • 原文地址:https://www.cnblogs.com/nymrli/p/9555849.html
Copyright © 2020-2023  润新知