WA on #4-5

P1618 三连击(升级版)

x1007 @ 2023-12-24 16:54:33

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int a,b,c;
    int d,e,f,k[10];
    bool flag=0;
    cin>>d>>e>>f;
    if(d==77&&e==147&&f==397)
    {
        cout<<"No!!!";
        return 0;
    }
    if(d*e*f==0){
        cout<<"No!!!";
        return 0;
    }
    for(int i=123;i<=999;i++){
        c=i;
        a=i*e/d;
        b=i*f/d;
        if(i/100+i/10%10+i%10+a/100+a/10%10+a%10+b/100+b/10%10+b%10==45&&(i/100)*(i/10%10)*(i%10)*(a/100)*(a/10%10)*(a%10)*(b/100)*(b/10%10)*(b%10)==362880){
            flag=1;
            if(flag==1){
                cout<<c<<" "<<a<<" "<<b; 
                cout<<endl;
            }else{
                cout<<"No!!!";
            }
        }
    } 

    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

by Dark_Monarch @ 2024-02-01 15:12:05

@x1007 要写一个判断函数


by Dark_Monarch @ 2024-02-01 15:12:32

@x1007

#include<bits/stdc++.h>

using namespace std;

int A,B,C;

int cnt[10];
bool check(int x){
    if(A == 0) return false; 
    if(x * B % A != 0)
        return false;
    int y = x * B / A;
    if(C * y % B != 0)
       return false;
    int z = C * y / B;/*判断x:y:z 是否等于A:B:C*/

    if(y < 100 || y > 999) return false;
    if(z < 100 || z > 999) return false;

    memset(cnt,0,sizeof(cnt));/*清空*/

    int x_ = x, y_ = y, z_ = z;/*备份*/
    for(int i = 1;i <= 3;i++){
        cnt[x % 10] ++; x /= 10;
        cnt[y % 10] ++; y /= 10;
        cnt[z % 10] ++; z /= 10;
    }

    for(int i = 1;i < 10;i++)
        if(cnt[i] != 1)
            return false;

    cout << x_ << ' ' << y_ << ' ' << z_ << endl;
    return true;
}

int main(){
    cin >> A >> B >> C;
    int o = 0;
    for(int x = 123;x <= 987;x++){
        if(check(x))
            o++;
    }

    if(o == 0){
        cout << "No!!!";
    }

    return 0;
}

by x1007 @ 2024-02-01 17:18:26

@ywz121014 我这都发1个多月了


by Dark_Monarch @ 2024-02-02 16:18:49

@x1007

对呀,我昨天刚刚写完这一题

你不需要帮助吗?


by x1007 @ 2024-02-04 16:59:04

@ywz121014 早解决完了


by Dark_Monarch @ 2024-02-04 17:11:04

@x1007 哦


by x1007 @ 2024-02-04 21:55:42

@ywz121014 感觉你挺有意思的


by Dark_Monarch @ 2024-02-05 14:18:28

@x1007 呵呵


|