80分求助!!!!

P1618 三连击(升级版)

511017802yrb @ 2023-12-20 20:36:33

#include<iostream>
#include<algorithm>
using namespace std;
int a, b, c;
int flag = 0;
void check(int p) {
    bool ak[10] = { 0 };
    int i = p,j = i / a * b, h = i / a * c;
    int p1 = j, p2 = h;
    if (p1 > 1000 || p2 > 1000 || p1 < 100 || p2 < 100)return;
    while (i) {
        ak[i % 10] = 1;
        i /= 10;
    }
    while (j) {
        ak[j % 10] = 1;
        j /= 10;
    }while (h) {
        ak[h % 10] = 1;
        h /= 10;
    }
    for (i = 1; i < 10; i++) {
        if (ak[i] == 0)return;
    }
    cout << p << " " << p1 << " " << p2 << endl;
    flag = 1;
}
int main(){
    cin >> a >> b >> c;
    int i;
    for (i = 123; i <= 987; i++) {
        check(i);
    }
    if(flag == 0)cout<<"No!!!";
    return 0;
}

by 511017802yrb @ 2023-12-20 20:37:08

最后一个过不了


by xiaoshumiao @ 2023-12-20 21:04:20

@511017802yrb

  1. 特判 a,b,c=0 的情况。


by 511017802yrb @ 2023-12-20 21:20:55

@xiaoshumiao 谢谢大佬,加了判断i模a不等于0后100了,但是hack 1 数据过不了


by xiaoshumiao @ 2023-12-20 22:00:24

@511017802yrb 见我说的 1. 。


by kelsie @ 2024-02-01 17:01:56

第一个数最大值不能大于333,可以改一下试试


|