Old Bill题解
Old Bill
http://www.nowcoder.com/questionTerminal/17a30153e092493e8b4d13f321343927
题目大概是说 已知买火鸡的个数,和总价的十位百位千位,让我们求火鸡的单价和总价的万位个位,其实就是模拟题嘛,读懂了题意就好做了。
#include <bits/stdc++.h> using namespace std; int main() { int n = -1, x = 0, y = 0, z = 0; int price = 0; int totalPrice = 0; int fadedPrice = 0; while (cin >> n) { bool flag = false; int numFront = 9, numRear = 9;//因为要最大值,所以从9开始 cin >> x >> y >> z; while (numFront > 0 && !flag) { while (numRear >= 0 && !flag) { fadedPrice = numFront * 10000 + numRear + x * 1000 + y * 100 + z * 10; price = fadedPrice / n; totalPrice = price * n; if (fadedPrice == totalPrice) { flag = true; break; } numRear--; } if (!flag) { numRear = 9; numFront--; } } if (numFront != 0)cout << numFront << " " << numRear << " " << price << endl; else cout << "0" << endl; } return 0; }