输入输出和测试点一致,为什么第一个挂了,第三个却通过了?求助大佬,qwq

P1618 三连击(升级版)

陆拾 @ 2019-09-30 11:54:05

include<stdio.h>

main() { int a=123,b=123,c=123,flag[9],i,a1,a2,a3,b1,b2,b3,c1,c2,c3,y=0,num=0; int A,B,C; for(i=1;i<=9;i++) flag[i]=0; //从1开始计算 scanf("%d%d%d",&A,&B,&C); while(a<=987&&b<=987&&c<=987) { y=0;//初始化 //printf("%d %d %d %d %d %d\n",a,B,C,b,A,C); if(aBC==bAC) { //printf("!!!\n"); if(aBC==cAB) { //printf("!!!\n"); a1=a%10; a2=(a/10)%10; a3=a/100; b1=b%10; b2=(b/10)%10; b3=b/100; c1=c%10; c2=(c/10)%10; c3=c/100;
flag[a1]=1; flag[a2]=1; flag[a3]=1; flag[b1]=1; flag[b2]=1; flag[b3]=1; flag[c1]=1; flag[c2]=1; flag[c3]=1; for(i=1;i<=9;i++) { if(flag[i]==0) {y=1;}//某一个个位数没出现 } if(y==0&&a<b&&b<c)//判断大小 { printf("%d %d %d\n",a,b,c); num++; } a++; for(i=1;i<=9;i++) flag[i]=0; //初始化 } /if(c==988) { b++; c=b; }/ //b已经固定,与a成比例,不能改变 else c++; } else b++; if(b==988)//已溢出 { a++; b=a+1;//b一定>a } } if(num==0) printf("No!!!"); return 0; }


by 陆拾 @ 2019-09-30 11:55:40

include<stdio.h>

main()

{

int a=123,b=123,c=123,flag[9],i,a1,a2,a3,b1,b2,b3,c1,c2,c3,y=0,num=0;
int A,B,C;
for(i=1;i<=9;i++)
flag[i]=0; //从1开始计算 
scanf("%d%d%d",&A,&B,&C);
while(a<=987&&b<=987&&c<=987)
{
    y=0;
    if(a*B*C==b*A*C)
    { 
        if(a*B*C==c*A*B)
        {
            a1=a%10;
            a2=(a/10)%10;
            a3=a/100;
            b1=b%10;
            b2=(b/10)%10;
            b3=b/100;
            c1=c%10;
            c2=(c/10)%10;
            c3=c/100;               
            flag[a1]=1;
            flag[a2]=1;
            flag[a3]=1;
            flag[b1]=1;
            flag[b2]=1;
            flag[b3]=1;
            flag[c1]=1;
            flag[c2]=1;
            flag[c3]=1;
            for(i=1;i<=9;i++)
            {
                if(flag[i]==0) {y=1;}//某一个个位数没出现 
            }
             if(y==0&&a<b&&b<c)//判断大小 
             {
                printf("%d %d %d\n",a,b,c);
                num++;
             }
             a++;
             for(i=1;i<=9;i++)
             flag[i]=0; //初始化 
        }
        /*if(c==988)
        {
            b++;
            c=b;
        }*/
        //b已经固定,与a成比例,不能改变 
        else c++;
    }
    else b++;
    if(b==988)//已溢出
    {
        a++;
        b=a+1;//b一定>a
     } 
}
if(num==0) printf("No!!!");
return 0;

}


by lygmh @ 2019-09-30 11:58:06

@陆拾

```cpp

你的代码

```


by 陆拾 @ 2019-10-06 13:37:21

@G_M_H 怎么了吗?


by Anyexyz @ 2019-10-16 22:57:02

码风不对

#include <stdio.h>
main(){
    int a = 123, b = 123, c = 123, flag[9], i, a1, a2, a3, b1, b2, b3, c1, c2, c3, y = 0, num = 0;
    int A, B, C;

    for (i = 1; i <= 9; i++)
        flag[i] = 0; //从1开始计算
    scanf("%d%d%d", &A, &B, &C);
    while (a <= 987 && b <= 987 && c <= 987) {
        y = 0;
        if (a * B * C == b * A * C) {
            if (a * B * C == c * A * B) {
                a1 = a % 10;
                a2 = (a / 10) % 10;
                a3 = a / 100;
                b1 = b % 10;
                b2 = (b / 10) % 10;
                b3 = b / 100;
                c1 = c % 10;
                c2 = (c / 10) % 10;
                c3 = c / 100;
                flag[a1] = 1;
                flag[a2] = 1;
                flag[a3] = 1;
                flag[b1] = 1;
                flag[b2] = 1;
                flag[b3] = 1;
                flag[c1] = 1;
                flag[c2] = 1;
                flag[c3] = 1;
                for (i = 1; i <= 9; i++) {
                    if (flag[i] == 0) {
                        y = 1;
                    }//某一个个位数没出现
                }
                if (y == 0 && a < b && b < c) {//判断大小
                    printf("%d %d %d\n", a, b, c);
                    num++;
                }
                a++;
                for (i = 1; i <= 9; i++)
                    flag[i] = 0; //初始化
            }
            /*if(c==988)
               {
                b++;
                c=b;
               }*/
            //b已经固定,与a成比例,不能改变
            else c++;
        }else b++;
        if (b == 988) {         //已溢出
            a++;
            b = a + 1;      //b一定>a
        }
    }
    if (num == 0) printf("No!!!");
    return 0;
}

|