除法 Division

除法

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/A

题意:

   输入正整数n按从小到大的顺序输出所有形如abcde/fghij=n的表达式,其中

a~j恰好为0~9的一个排列(可以有前导0),2<=n<=79。

Sample Input 

61
62
0

 

Sample Output 

There are no solutions for 61.

79546 / 01283 = 62
94736 / 01528 = 62

 

 分析:

     由fghij可以算出abcde,所有我们只需要枚举fghij,然后判断abcdefghij这些数字是否都不相等即可。

注意输出的格式(空格)。

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int b[10];
 5 int per(int x,int y)
 6 {int i;
 7 if(y>98765) return 0;
 8 for(i=0;i<10;i++)
 9  b[i]=0;
10 if(x<10000)   b[0]=1;
11 while(x)
12 {
13     b[x%10]=1;
14     x=x/10;
15 }
16 while(y)
17 {
18 b[y%10]=1;
19 y=y/10;
20 }
21 int sum=0;
22 for( i=0;i<10;i++)
23  sum=sum+b[i];
24 return (sum==10);
25 }
26 int main()
27 { 
28     int n,c=0,i,count;
29     scanf("%d",&n);
30    while(n)
31    { 
32       if(c++) cout<<endl;
33       count=0;
34      for(i=1234;i<100000;i++)
35      {
36        if(per(i,i*n))  
37        {
38            printf("%05d / %05d = %d\n",i*n,i,n);
39           count++;
40        }
41      }
42      if(count==0)
43          printf("There are no solutions for %d.\n",n);
44      scanf("%d",&n);
45      }
46    
47 return 0;
48 }

 

转载于:https://www.cnblogs.com/fenhong/p/4680263.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值