UVa 725(简单枚举)
来源:互联网 发布:网络部主要职责 编辑:程序博客网 时间:2024/06/05 16:24
Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, where. That is,
abcde / fghij =N
where each letter represents a different digit. The first digit of one of the numerals is allowed to be zero.
Input
Each line of the input file consists of a valid integer N. An input of zero is to terminate the program.Output
Your program have to display ALL qualifying pairs of numerals, sorted by increasing numerator (and, of course, denominator).Your output should be in the following general form:
xxxxx / xxxxx =N
xxxxx / xxxxx =N
.
.
In case there are no pairs of numerals satisfying the condition, you must write ``There are no solutions for N.". Separate the output for two different values of N by a blank line.
Sample Input
61620
Sample Output
There are no solutions for 61.79546 / 01283 = 6294736 / 01528 = 62
//思路:从b等于1234开始枚举生成a,然后判断a和b是否满足要求(巧用了sprintf先保存到buf,再sort) 还有%05d解决了前导0的问题
AC源码:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;int main(){char buf[15];int kase=0,n;while(cin>>n&&n){int cnt=0;if(kase++)printf("\n");for(int b=1234;;++b){int a=b*n;sprintf(buf,"%05d%05d",a,b);if(strlen(buf)>10)break;sort(buf,buf+10);bool ok=true;for(int i=0;i<10;++i)if(buf[i]!='0'+i)ok=false;if(ok){++cnt;printf("%05d / %05d = %d\n",a,b,n);}}if(!cnt)printf("There are no solutions for %d.\n",n);}return 0;}
阅读全文
0 0
- uva 725 简单枚举
- UVa 725(简单枚举)
- UVA 725 简单枚举
- uva 725 Division 简单枚举
- Uva 725 Division(简单枚举)
- UVA 725 Division(暴力枚举 简单)
- UVa 725 简单枚举+整数转换为字符串
- UVa 725----Division(枚举)
- UVA - 11059 Maximum Product (简单枚举)
- UVA - 10167 - Birthday Cake (简单枚举)
- Uva 11059 Maximum Product(简单枚举)
- Uva 10976 Fractions Again(简单枚举)
- UVa 725 Division(枚举)
- UVa--725 Division(枚举)
- UVa - 725 - Division(暴力枚举)
- UVa 216 - Getting in Line 回溯,简单递归枚举
- uva 10112 - Myacm Triangles 简单计算几何+枚举
- uva 10167 - Birthday Cake(最简单枚举)
- Windows Socket 编程_ 简单的服务器/客户端程序
- 013. Spring JdbcTemplate访问数据库
- Linq一些方法整理
- 阿里云centos系统安装svn,tomcat,mysql外网连接不上问题解决
- 读书笔记-大型网站系统与Java中间件9
- UVa 725(简单枚举)
- chromium中的GN构建系统
- 下拉框中使用json格式数据并且支持模糊搜索
- vue脚手架项目打包后路由视图不显示问题
- INTP
- mongodb实现简单的增删改查
- padding和margin的区别
- Android中的“再按一次返回键退出程序”实现
- oracle-rac 遇到的错误