首页 > 代码库 > 九度OJ 1036 Old Bill (模拟)

九度OJ 1036 Old Bill (模拟)

题目1036:Old Bill

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:2302

解决:1211

题目描述:

    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

#include<stdio.h>
int N;
int X;
int Y;
int Z;
int A;
int B;
int ans;
int check(int num){
    int sum=N*num;
    if((sum/10)%10==Z&&(sum/100)%10==Y&&(sum/1000)%10==X)
    {
        A=(sum/10000)%10;
        B=(sum%10);
        ans=num;
        return 1;
    }
    return 0;
}
void output()
{
    printf("%d %d %d\n",A,B,ans);
}
int main(int argc, char *argv[])
{
    freopen("1036.in","r",stdin);
    while(~scanf("%d",&N))
    {
        scanf("%d %d %d",&X,&Y,&Z);
        int M=99999/N;
        for(int i=M;;--i)
        {
            if(check(i)){
                output();
                break;
            }
            if(i<=0){
                printf("0\n");
                break;
            }
        }
    }
    return 0;
}


九度OJ 1036 Old Bill (模拟)