题解 | #Old Bill#
Old Bill
https://www.nowcoder.com/practice/17a30153e092493e8b4d13f321343927
写于2024.3.18
#include <iostream> #include <algorithm> #include <cstring> using namespace std; int main() { int i, j, k, n, x, y, z, hightest, lowest; // hightest, lowest分别表示最高位和最低位,即万位和个位 cin >> n; // 有n只火鸡 cin >> x >> y >> z; int min = z * 10 + y * 100 + x * 1000; // 计算0xyz0的值 // int maxhigh, maxlow; for (hightest = 9; hightest > 0; hightest--) { for (lowest = 9; lowest >= 0; lowest--) { if ((min + hightest * 10000 + lowest) % n == 0) // 符合条件的情况,可以输出 { // cout << (min + hightest * 10000 + lowest) << endl; cout << hightest << " " << lowest << " " << (min + hightest * 10000 + lowest) / n << endl; return 0; } } } cout << "0" << endl; return 0; }