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
Sample Output
Source: Asia 2003, Seoul (South Korea)
题意弄懂了就好做了,比较水,就是求一个最大五位数能整除n的,两层for循环,注意第一层不能等于0,会WA
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; }
相关文章推荐
- 游戏系统开发笔记(二)——开发流程和项目管理
- MQX 之串口使用
- HTML简要内容
- UINavigationBar导航栏相关设置
- 游戏系统开发笔记(一)——立项、分工和制作基础
- js验证真实姓名与身份证号,手机号
- Java考题
- [利用好互联网]两招教你随时关注别人博客是否有更新
- 数据结构(九)满二叉树深度计算
- ios学习之自定义窗口的激活
- Scala学习笔记16【Scala闭包代码实例】
- [Django模板系统]大致了解Django的模板系统
- Linux 下安装Samba 文件共享服务器
- Xcode和github入门详细教程
- leetcode之Implement Queue using Stacks
- 【C语言】求最大最小值
- 自定义Hive Sql Job分析工具
- java hashtable 和 hashmap的区别
- 游戏系统开发笔记(序)——因由、感想与目的
- linux 通过scp 复制备份恢复mysql数据表