博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA 725 - Division
阅读量:5101 次
发布时间:2019-06-13

本文共 2182 字,大约阅读时间需要 7 分钟。

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 $2\le N \le 79$. 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.

 

Each line of the input file consists of a valid integer 
N
. An input of zero is to terminate the program.

 

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.

 

61620

 

There are no solutions for 61.79546 / 01283 = 6294736 / 01528 = 62

#define RUN#ifdef RUN#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define MAXN 1000bool check(int a, int b){ int repeat[11] = {0}; if(a < 10000){ repeat[0]++; } if(b < 10000){ repeat[0]++; } if(repeat[0] > 1){ return false; } while(a != 0){ int remain = a % 10; if(repeat[remain] != 0){ return false; } repeat[remain]++; a /= 10; } while(b != 0){ int remain = b % 10; if(repeat[remain] != 0){ return false; } repeat[remain]++; b /= 10; } return true;}void play(int n){ int fghij = 1234; int abcde = n * fghij; bool found = false; for(; abcde<100000; ++fghij){ abcde = n * fghij; if(check(abcde, fghij)){ found = true; //自动补零 printf("%05d / %05d = %d\n", abcde, fghij, n); } } if(!found){ printf("There are no solutions for %d.\n", n); }}int main(){#ifndef ONLINE_JUDGE freopen("725.in", "r", stdin); freopen("725.out", "w", stdout); #endif int n; // 有用的技巧来避免结尾多输出一空行 bool blank = false; while(scanf("%d",&n)==1 && n){ if(blank){ printf("\n"); } play(n); blank = true; }}#endif

转载于:https://www.cnblogs.com/AlgoWing/archive/2013/03/07/3189594.html

你可能感兴趣的文章
uboot分析:uboot的启动过程分析
查看>>
tmux的简单快捷键
查看>>
springboot笔记04——读取配置文件+使用slf4j日志
查看>>
[Swift]LeetCode653. 两数之和 IV - 输入 BST | Two Sum IV - Input is a BST
查看>>
[Swift]LeetCode922.按奇偶排序数组 II | Sort Array By Parity II
查看>>
微信小程序的wxml文件和wxss文件在webstrom的支持
查看>>
Html5 离线页面缓存
查看>>
[php]在PHP中读取和写入WORD文档的代码
查看>>
WCF傻瓜模式写程序
查看>>
《绿色·精简·性感·迷你版》易语言,小到不可想象
查看>>
Java Web学习总结(13)Listener监听器
查看>>
开始Flask项目
查看>>
Ruby:多线程队列(Queue)下载博客文章到本地
查看>>
Android打包key密码丢失找回
查看>>
03 jQuery动画
查看>>
医药箱APP静态小项目
查看>>
安装使用eclipse
查看>>
VC6.0调试技巧(一)(转)
查看>>
linux命令
查看>>
类库与框架,强类型与弱类型的闲聊
查看>>