1036.Old Bill
2014-05-25 00:20
337 查看
题目描述:
Among grandfather's papers a bill was found.
72 turkeys $_679_
The first and the last digits of the number that obviously represented the total price of those turkeys are replaced here by blanks (denoted _), for they are faded and are illegible. What are the two faded digits and what was the price of one turkey?
We want to write a program that solves a general version of the above problem.
N turkeys $_XYZ_
The total number of turkeys, N, is between 1 and 99, including both. The total price originally consisted of five digits, but we can see only the three digits in the middle. We assume that the first digit is nonzero, that the price of one turkeys is an integer
number of dollars, and that all the
turkeys cost the same price.
Given N, X, Y, and Z, write a program that guesses the two faded digits and the original price. In case that there is more than one candidate for the original price, the output should be the most expensive one. That is, the program is to report the two faded
digits and the maximum price per turkey for the turkeys.
输入:
The first line of the input file contains an integer N (0<N<100), which represents the number of turkeys. In the following line, there are the three decimal digits X, Y, and Z., separated by a space, of the original price $_XYZ_.
输出:
For each case, output the two faded digits and the maximum price per turkey for the turkeys.
样例输入:
72
6 7 9
5
2 3 7
78
0 0 5
样例输出:
3 2 511
9 5 18475
0
#include <iostream>
using namespace std;
int main()
{
int N, X, Y, Z;
while (cin >> N >> X >> Y >> Z)
{
bool flag = false;
for (int i = 9; i > 0; --i)
{
if (!flag) //判断是否应该执行第二个循环
{
for (int j = 9; j >= 0; --j)
{
int sum = i * 10000 + X * 1000 + Y * 100 + Z * 10 + j;
if (sum % N == 0)
{
cout << i << " " << j << " " << sum / N << endl;
flag = true;
break; //找到之后直接跳出第二个循环,剩下的循环不执行。
}
}
}
}
if (flag == false)
cout << 0 << endl;
}
return 0;
}
Among grandfather's papers a bill was found.
72 turkeys $_679_
The first and the last digits of the number that obviously represented the total price of those turkeys are replaced here by blanks (denoted _), for they are faded and are illegible. What are the two faded digits and what was the price of one turkey?
We want to write a program that solves a general version of the above problem.
N turkeys $_XYZ_
The total number of turkeys, N, is between 1 and 99, including both. The total price originally consisted of five digits, but we can see only the three digits in the middle. We assume that the first digit is nonzero, that the price of one turkeys is an integer
number of dollars, and that all the
turkeys cost the same price.
Given N, X, Y, and Z, write a program that guesses the two faded digits and the original price. In case that there is more than one candidate for the original price, the output should be the most expensive one. That is, the program is to report the two faded
digits and the maximum price per turkey for the turkeys.
输入:
The first line of the input file contains an integer N (0<N<100), which represents the number of turkeys. In the following line, there are the three decimal digits X, Y, and Z., separated by a space, of the original price $_XYZ_.
输出:
For each case, output the two faded digits and the maximum price per turkey for the turkeys.
样例输入:
72
6 7 9
5
2 3 7
78
0 0 5
样例输出:
3 2 511
9 5 18475
0
#include <iostream>
using namespace std;
int main()
{
int N, X, Y, Z;
while (cin >> N >> X >> Y >> Z)
{
bool flag = false;
for (int i = 9; i > 0; --i)
{
if (!flag) //判断是否应该执行第二个循环
{
for (int j = 9; j >= 0; --j)
{
int sum = i * 10000 + X * 1000 + Y * 100 + Z * 10 + j;
if (sum % N == 0)
{
cout << i << " " << j << " " << sum / N << endl;
flag = true;
break; //找到之后直接跳出第二个循环,剩下的循环不执行。
}
}
}
}
if (flag == false)
cout << 0 << endl;
}
return 0;
}
相关文章推荐
- 题目1036 Old Bill 九度Online Judge
- 九度oj-1036-old bill
- 题目1036:Old Bill
- 九度 题目1036:Old Bill
- 九度OJ 1036 Old Bill (模拟)
- 九度OJ 1036:Old Bill
- 九度OJ 1036:Old Bill (老比尔) (基础题)
- 九度OnlineJudge之1036:Old Bill
- 九度OJ 1036:Old Bill (老比尔) (基础题)
- 题目1036:Old Bill
- 九度OJ题目1036:Old Bill
- ZOJ 2679 Old Bill(STL应用)
- 上交复试07年机考题(old bill)
- ZOJ 2679 Old Bill
- ZOJ.2679 Old Bill【水】 2015/10/12
- ZOJ 2679 Old Bill(数学)
- ZOJ 2679 Old Bill(数学题)
- ZOJ 2679 Old Bill ||ZOJ 2952 Find All M^N Please 两题水题
- ZOJ 2679 Old Bill ||ZOJ 2952 Find All M^N Please 两题水题
- Old Bill