1 条题解

  • 0
    @ 2025-2-14 20:52:08

    C :

    #include<stdio.h>
    int Magic(int m);
    int main()
    {
    	int m,ret;
    	scanf("%d",&m);
    	ret=Magic(m);
    	if(ret!=1)
    	    printf("The sum you calculated is wrong!\n");
    	return 0;
    }
    int Magic(int m)
    {
    	int a,b,c,n;
    	for(a=1;a<9;a++)
    	{
    		for(b=1;b<9;b++)
    		{
    			for(c=1;c<9;c++)
    			{
    				n=122*a+212*b+221*c;
    				if(m==n)
    				{
    					printf("%d\n",100*a+10*b+c);
    					return 1;
    				}
    			}		
    		}
    	}
    	return 0;
    }
    

    C++ :

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    using namespace std;
    int main()
    {
    	int n;
    	scanf("%d",&n);
    	for(int a=1;a<=9;++a)
    	{
    		for(int b=0;b<=9;++b)
    		{
    			for(int c=0;c<=9;++c)
    			{
    				if(a*100+c*10+b+b*100+a*10+c+b*100+c*10+a+c*100+a*10+b+c*100+b*10+a==n)
    				{
    					printf("%d",a*100+b*10+c);
    					return 0;
    				}
    			}
    		}
    	}
    	printf("The sum you calculated is wrong!");
    	return 0;
    }
    
    • 1

    【设计型】第7章:函数7.10(选做) 数字魔术游戏

    信息

    ID
    473
    时间
    1000ms
    内存
    2MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者