Division

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.

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 

61
62
0

Sample Output 

There are no solutions for 61.

79546 / 01283 = 62
94736 / 01528 = 62
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

#define MAX(a,b) ((a)>(b) ? (a):(b))
#define MIN(a,b) ((a)<(b) ? (a):(b))

int main()
{
	freopen("b.txt","w",stdout);
	int n;
	while(scanf("%d",&n)!=EOF&&n)
	{
		int i,b,c=1233,flag=1;
		char a[99];
		while(c++)
		{
			b=c*n;
		    sprintf(a,"%05d%05d",b,c);
		    if(strlen(a)>10) break;
		    int s[12]={0};
		    for(i=0;i<10;i++)
		     {
				if(s[a[i]-'0']!=0) break;
		        else s[a[i]-'0']++;
			}
		    if(i==10) {printf("%05d / %05d = %d\n",b,c,n); flag=0;}
		}
		if(flag) printf("There are no solutions for %d.\n",n);
		printf("\n");
	}
	return 0;
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Python中,使用"/"操作符进行除法计算时,结果默认是整数除法,即只保留整数部分。如果想要得到精确的除法结果,可以在程序中导入division特征,即使用"from __future__ import division"语句。这样,"/"操作符执行的就是精确算法,可以得到浮点数结果。 给定一个函数arithmetic(x, y, operator),它接收两个数和一个操作符作为参数,根据操作符的不同,返回相应的计算结果。函数内部使用了字典来存储不同操作符对应的计算结果,然后通过调用字典的get方法来获取结果。在函数内部,没有使用return语句的函数将返回None。在Python 2.7.6中,默认的除法运算是整数除法,即结果只保留整数部分。如果希望执行精确除法,需要先导入division特征。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [python division如何取整](https://blog.csdn.net/weixin_33140809/article/details/114450670)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [《零基础学Python》模块与函数【五】](https://blog.csdn.net/qq_44414444/article/details/117791245)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值