Old bill
题目描述
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.
示例1
输入
复制
72
6 7 9
5
2 3 7
78
0 0 5
输出
复制
3 2 511
9 5 18475
0
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
int n, x, y, z;
while ((scanf("%d%d%d%d", &n, &x, &y, &z)) != EOF) {
int i = 0, j = 0, num = 0, price = 0, mi = 0, mj = 0, total = 0;
num += (1000 * x + 100 * y + 10 * z);
for ( i = 1; i < 10; ++i) {
for ( j = 0; j < 10; ++j) {
total = (num + 10000 * i + j);
if (total % n == 0) {
mi = i;
mj = j;
}
}
}
if (mi == 0 && mj == 0) {
printf("0\n");
}
else {
price = (num + 10000 * mi + mj) / n;
printf("%d %d %d\n", mi, mj, price);
}
}
return 0;
}
在需要一直输入时可以使用:while((scanf("%d%d%d%d", &n, &x, &y, &z)) != EOF)
这是一个关于编程算法的问题,要求编写一个程序来解决类似旧账单上的问题。给定购买的火鸡数量N,以及账单上中间的三个数字X、Y和Z,程序需要找出缺失的第一和第五个数字,并计算出火鸡的单价。程序通过尝试所有可能的组合来找到使总价能被火鸡数量整除的数字,如果存在多个解决方案,则选择使单价最高的那个。输入包括火鸡数量和账单的中间三位数字,输出为缺失的两个数字和最高单价。
859

被折叠的 条评论
为什么被折叠?



