九度OJ 1036:Old Bill

来源:互联网 发布:yessat 知乎 编辑:程序博客网 时间:2024/05/16 16:13

题目描述:
Among grandfather’s papers a bill was found.
72 turkeys 679Thefirstandthelastdigitsofthenumberthatobviouslyrepresentedthetotalpriceofthoseturkeysarereplacedherebyblanks(denoted),fortheyarefadedandareillegible.Whatarethetwofadeddigitsandwhatwasthepriceofoneturkey?Wewanttowriteaprogramthatsolvesageneralversionoftheaboveproblem.Nturkeys_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

#include <cstdio>using namespace std;int main(){    int n,x,y,z;    while(scanf("%d",&n) != EOF){        scanf("%d%d%d",&x,&y,&z);        bool flag = true;        for(int i = 9;i > 0;i--){            for(int j = 9;j >= 0;j--){                int tmp = 10000*i + 1000*x + 100*y + 10*z + j;                if(tmp % n == 0){                    printf("%d %d %d\n",i,j,tmp/n);                    flag = false;                    break;                }            }            if(flag == false)break;        }        if(flag == true)printf("0\n");    }}
原创粉丝点击