哪里错了??!!

P1618 三连击(升级版)

zhangyichen666 @ 2024-07-14 18:47:57

#include<bits/stdc++.h>
using namespace std;
int a,b,c,a1,b1,c1;
int bsa,bsb,bsc;
bool sf=0,sf1=0;
int sz[11];
int main(){
    cin>>bsa>>bsb>>bsc;
    for(int i=123;i<=987;i++){
        a=i*bsa;
        b=i*bsb;
        c=i*bsc;
        a1=a;
        b1=b;
        c1=c;
        if(i%10==0){
            continue;
        }
        while(a){
            sz[a%10]++;
            a/=10;
        }
        while(b){
            sz[b%10]++;
            b/=10;
        }
        while(c){
            sz[c%10]++;
            c/=10;
        }
        for(int j=1;j<=9;j++){
            if(sf==1){
                continue;
            }
            if(sz[j]>=2||sz[j]==0){
                sf=1;
                sz[j]=0;
                cout<<j;
                continue;
            }
            sf=0;
            sz[j]=0;
        }
        if(sf==1){
            sf=0; 
            continue;
        }
        cout<<a1<<" "<<b1<<" "<<c1<<"\n";
        sf=0;
        sf1=1;
    }
    if(sf1==0){
        cout<<"No!!!";
    }
    return 0;
}

by Clare613 @ 2024-07-14 19:31:19

我建议你开始全部清空。

memset(sz,0,sizeof(sz));

by Clare613 @ 2024-07-14 19:31:53

然后是从1到999遍历


by Clare613 @ 2024-07-14 19:32:58

最后一个错是a,b,c乘了后要小于1000


by Clare613 @ 2024-07-14 19:33:18

@zhangyichen666


by Clare613 @ 2024-07-14 19:39:44

改成这样:

#include<bits/stdc++.h>
using namespace std;
int a,b,c,a1,b1,c1;
int bsa,bsb,bsc;
bool sf=0,sf1=0;
int sz[11];
int main(){
    cin>>bsa>>bsb>>bsc;
    for(int i=1;i<=999;i++){
        a=i*bsa;
        b=i*bsb;
        c=i*bsc;
        a1=a;
        b1=b;
        c1=c;
        if(i%10==0){
            continue;
        }
        if(a>=1000||b>=1000||c>=1000){
            continue;
        }
        while(a){
            sz[a%10]++;
            a/=10;
        }
        while(b){
            sz[b%10]++;
            b/=10;
        }
        while(c){
            sz[c%10]++;
            c/=10;
        }
        for(int j=1;j<=9;j++){
            if(sf==1){
                sz[j]=0;
                continue;
            }
            if(sz[j]!=1){
                sz[j]=0;
                sf=1;
                continue;
            }
            sf=0;
            sz[j]=0;
        }
        if(sf==1){
            sf=0; 
            continue;
        }
        cout<<a1<<" "<<b1<<" "<<c1<<"\n";
        sf=0;
        sf1=1;
    }
    if(sf1==0){
        cout<<"No!!!";
    }
    return 0;
}

by zhangyichen666 @ 2024-07-14 19:45:34

@Clare613 谢谢大佬,已通


|