求助dalao

P1618 三连击(升级版)

littlefrog @ 2019-08-07 10:08:26

#include <bits/stdc++.h>
using namespace std;
inline bool judge(int a,int b,int c) {
    int cnt[10];
    memset(cnt,0,sizeof(cnt));
    string q,w,e;
    q = to_string(a);
    w = to_string(b);
    e = to_string(c);
    if(q.size()==3&&w.size()==3&&e.size()==3) {
        for(int i = 0;i<q.size();++i) {
            cnt[q[i]-'0']++;
        }
        for(int i = 0;i<w.size();++i) {
            cnt[w[i]-'0']++;
        }
        for(int i = 0;i<e.size();++i) {
            cnt[e[i]-'0']++;
        }
        for(int i = 1;i<=9;++i) {
            if(cnt[i]!=1) {
                //cout<<"Char Error:"<<cnt[i]<<" "<<i+'0'<<endl;
                return 0;
            }
        }
        return 1;
    } else {
        //cout<<"length Error."<<endl;;
        return 0;
    }
}
int main() {
    int a,b,c;
    cin>>a>>b>>c;
    bool flag = 0;
    for(int i = 100;i<=999;++i) {
        int j = i*a;
        int k = i*b;
        int l = i*c;
        if(judge(j,k,l)) {
            flag++;
            cout<<j<<" "<<k<<" "<<l<<endl;
        }
    }
    if(!flag) {
        cout<<"No!!!";
        return 0;
    }
}

by Elzat @ 2019-08-07 10:14:02

刚才说错了

int j = i;
int k = i*b/a;
int l = i*c/a;

应该是这样


by littlefrog @ 2019-08-08 08:16:32

谢谢dalao


|