【c/c++】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.

在祖父的文件中发现了一张账单。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

思路

循环遍历两个数字找到可能的整数结果,因为取最贵的原始价格,直接从9倒序遍历到出现结果即可。

代码
#include<bits/stdc++.h>

int main(){
    int num;
    int x,y,z;
    int sum;
    while(scanf("%d\n%d %d %d",&num,&x,&y,&z)!=EOF){
        int a,b,price=0; //账单不见的两位数字 单价
        for(int i=9;i>0;i--){
            for(int j=9;j>=0;j--){
                sum = i*10000+x*1000+y*100+z*10+j;
                if(sum%num==0){
                    a = i;
                    b = j;
                    price = sum/num;
                    break;
                }//if
            }//for
            if(price){
                printf("%d %d %d\n",a,b,price);
                break;
            }
        }//for
        if(!price){
            printf("0\n");
        }
    }//while    
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶柖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值