UVA725 - Division

链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=666


725   Division

Write a program that finds and displaysall pairs of 5-digit numbers that between them use the digits 0 through 9 onceeach, such thatthe first number dividedby the secondis equal to an integer N , where 2 ≤ N ≤ 79. That is,

abcde

= N

fghij

where each letter representsa different digit. The first digit of one of the numerals is allowedto be zero.

 

Input

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

 

Output

Your program have to display ALL qualifying pairs of numerals, sortedby increasing numerator(and, of course,denominator).

Your output should be in the following generalform:

xxxxx / xxxxx = N xxxxx / xxxxx = N

.

.

 

In case there are no pairs of numerals satisfyingthe 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

61

62

0

 

Sample Output

There are no solutions for 61.

 

79546 / 01283 = 62

94736 / 01528 = 62


题意:

键入 N ,求由 0~9 组成的 abcde / fghij = N 满足的项

思路:

直接暴力走过,可知 abcde 组成的数字是 12345 - 98765 ,拟写一个判断 0 - 9 的数字是否都出现的函数即可。

但是卡的事 是格式

AC CODE:

#include<stdio.h>
#include<cstring>
#include<algorithm>
#define HardBoy main()
#define ForMyLove return 0;
using namespace std;
const int MYDD = 1103;

int GetBit[10];/*存储数位的数字*/
bool Judge(int x, int y) {
	memset(GetBit, 0, sizeof(GetBit));
	while(x) {/*Bug 2016年12月5日19:07:30 -> 写成 if 判断*/
		GetBit[x%10]++;
		x /= 10;
	}
	while(y) {
		GetBit[y%10]++;
		y /= 10;
	}
	for(int i = 1; i <= 9; i++) {/*不必判断 0 */
		if(GetBit[i] != 1) {
			return false;
		}
	}
	return true;
}

int HardBoy {
	int n;
	while(scanf("%d", &n) && n) {
		int flag = 0;
		for(int j = 12345; j <= 98765; j++) {
			if(j%n == 0) {
				int zi = j, mu = j/n;
				if(Judge(zi, mu)) {
					printf("%d / %05d = %d\n", j, j/n, n);
					flag = 1;
				}
			}
		}
		if(!flag) printf("There are no solutions for %d.\n", n);
		printf("\n");
	}
	ForMyLove
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值