描述
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.
翻译:
在祖父的文件中发现了一张帐单:72 只火鸡共 $_679_ 。显然代表这些火鸡总价的数字的第一个和最后一个数字在这里被空白(标记为_)所取代,因为它们已经褪色,难以辨认。那两个褪色的数字是什么,一只火鸡的价格是多少?我们要编写一个程序来解决上述问题。N只火鸡共$_XYZ_ N只火鸡的总数在1到99之间。总价本来是五位数字,但是我们只能看到中间的三位数字。我们假设第一个数字非零,一只火鸡的价格是整数美元,所有火鸡的价格相同。给定N, X, Y和Z,编写一个程序,猜测两个褪色的数字和原始价格。如果原始价格有多个候选,则输出应该是最昂贵的。也就是说,程序要算出这两个褪色的数字和每只火鸡的最高价格。
输入描述:
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_.
翻译:
输入文件的第一行包含一个整数N (0<N<100),它表示火鸡的数量。在下一行中,原始价格$_XYZ_有三个十进制数字X、Y和Z,用空格分隔。
输出描述:
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<bits/stdc++.h>
using namespace std;
int main(){
int n,x,y,z,money=0,ans,price,maxi,maxj,maxprice=-1;
while (scanf("%d%d%d%d",&n,&x,&y,&z)!=EOF) {//循环输入多组数据
ans=0;
for(int i=1;i<=9;i++){//i是最高位不能为0
for(int j=0;j<=9;j++){//j是最低位可以为0
money=i*10000+x*1000+y*100+z*10+j;
price=money/n;
if(price*n==money){
ans=1;
if(maxprice<price){//记录最大单价
maxprice=price;
maxi=i;
maxj=j;
}
}
}
}
if(ans){
printf("%d %d %d\n",maxi,maxj,maxprice);
}
else
printf("0\n");
}
}
标签:digits,火鸡,Old,数字,turkeys,price,Bill,faded,考研
From: https://blog.csdn.net/weixin_56259838/article/details/145193263