OJ_1036

来源:互联网 发布:伟大的艺术家 知乎 编辑:程序博客网 时间:2024/05/21 09:00
#include <iostream>using namespace std;void func(){     int n;     int x,y,z;     while(cin>>n>>x>>y>>z)     {                           bool flag=false;                           int reta=0;                           int retb=0;                           int price=0;                           int oldsum=x*1000+y*100+z*10;                           int sum=0;                           for(int i=9;i>=1;i--)                           {                                   for(int j=9;j>=0;j--)                                   {                                                                                      sum=i*10000+oldsum+j;                                                                                      if(sum%n==0)                                           {                                                                                                        flag=true;                                                  reta=i;                                                  retb=j;                                                  price=sum/n;                                                  break;                                           }                                   }                                   if(flag)                                   break;                           }                           if(flag)                           cout<<reta<<" "<<retb<<" "<<price<<endl;                           else                           cout<<"0"<<endl;     }            }int main(int argc, char *argv[]){    //printf("Hello, world\n");func();return 0;}

从9开始循环,计算模是否为0的情况

题目描述:

    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.

// 给出NXYZ,写一段程序猜出    形式如_XYZ_缺少的两个数字,以及火鸡的原始价格。如果有多过一个的价格,输出最贵的。

输入:

    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.

样例输入:
726 7 952 3 7780 0 5
样例输出:
3 2 5119 5 184750

0 0
原创粉丝点击