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.
输入描述:
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.
要点 只输出最大的一个整数单价 因此要跳出两层for循环 借助flag 使用两次break 注意总价是五位数 在遍历的时候第一个位置不能为0否则就变成四位数了
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
int x,y,z;
int flag=0;
while(scanf("%d",&n)!=EOF){
scanf("%d%d%d",&x,&y,&z);
for(int i=9;i>0;--i){
for(int j=9;j>=0;--j){
int total=i*10000+x*1000+y*100+z*10+j;
if(double(total)/n==total/n){
printf("%d %d %d\n",i,j,total/n);
flag=1;break;
}
}if(flag==1){
break;
}
}
if(flag==0){
printf("0\n");
}
}
}