您的位置:首页 > 其它

九度OJ 1036:Old Bill

2018-03-04 15:26 483 查看
题目描述:    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
思路:
火鸡的总价格中间三位已知x,y,z,最高位不为零。要买的火鸡总数为n且火鸡单价为整数。输出一组最高位和最低位的值,要求火鸡单价最高。

#include<stdio.h>
#include<string.h>

int main() {
int n,x,y,z,flag=0;
while(~scanf("%d%d%d%d",&n,&x,&y,&z)){
flag=0;
for(int i=9; i>=1; i--) {
for(int j=9; j>=0; j--) {
int tmp=i*10000+x*1000+y*100+z*10+j;
if(tmp%n==0) {
printf("%d %d %d\n",i,j,tmp/n);flag=1;
break;
}
}
if(flag==1)
break;
}
if(!flag)
{
printf("0\n");
}

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  枚举