P1008 [NOIP 1998 普及组] 三连击

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

bool check(int A, int B, int C) {
    // 将A, B, C拼接成一个字符串
    string s = to_string(A) + to_string(B) + to_string(C);
    // 检查字符串长度是否为9
    if (s.length() != 9) return false;
    // 检查是否包含1到9的所有数字
    sort(s.begin(), s.end());
    return s == "123456789";
}

int main() {
    for (int A = 123; A <= 329; A++) {
        int B = 2 * A;
        int C = 3 * A;
        if (check(A, B, C)) {
            cout << A << " " << B << " " << C << endl;
        }
    }
    return 0;
}

0 条评论

目前还没有评论...