您的位置:首页 > 其它

ZOJ.2679 Old Bill【水】 2015/10/12

2015-10-12 22:03 411 查看
Old Bill

Time Limit: 2 Seconds
Memory Limit: 65536 KB

Among grandfather��s papers a bill was found:

72 turkeys $_679_
The first and the last digits of the number that obviously represented thetotal price of those turkeys are replaced here by blanks (denoted _), forthey are faded and are now illegible. What are the two faded digits andwhat was the price of one turkey?

We want to write a program that solves a general version of the aboveproblem:

N turkeys $_XYZ_
The total number of turkeys, N, is between 1 and 99, including both. Thetotal price originally consisted of five digits, but we can see only the threedigits in the middle. We assume that the first digit is nonzero, that theprice of one turkey is an integer
number of dollars, and that all the turkeyscost the same price.

Given N, X, Y , and Z, write a program that guesses the two faded digitsand the original price. In case that there is more than one candidate forthe 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 perturkey for the turkeys.

Input

The input consists of T test cases. The number of test cases (T) is givenon the first line of the input file. The first line of each test case contains aninteger N (0 < N < 100), which represents the number of turkeys. In thefollowing line, there are the
three decimal digits X, Y , and Z, separatedby a space, of the original price $_XYZ_.

Output

For each test case, your program has to do the following. For a test case,there may be more than one candidate for the original price or there isnone. In the latter case your program is to report 0. Otherwise, if thereis more than one candidate for the original
price, the program is to reportthe two faded digits and the maximum price per turkey for the turkeys.The following shows sample input and output for three test cases.

Sample Input

3
72
6 7 9
5
2 3 7
78
0 0 5

Sample Output

3 2 511
9 5 18475
0


Source: Asia 2003, Seoul (South Korea)

题意弄懂了就好做了,比较水,就是求一个最大五位数能整除n的,两层for循环,注意第一层不能等于0,会WA

#include<iostream>
#include<cstdio>

using namespace std;

int main(){
int n,x,y,z;
int t;
cin>>t;
while(t--){
cin>>n;
cin>>x>>y>>z;
bool flag = false;
for( int i = 9 ; i > 0 ; --i ){
for( int j = 9 ; j >= 0 ; --j ){
int ret = i * 10000 + x*1000 + y*100 + z*10 + j;
if( ret % n == 0 ){
printf("%d %d %d\n",i,j,ret/n);
flag = true;
break;
}
}
if( flag ) break;
}
if( !flag ) printf("0\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: