• 除法 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
    ",i*n,i,n);
    39           count++;
    40        }
    41      }
    42      if(count==0)
    43          printf("There are no solutions for %d.
    ",n);
    44      scanf("%d",&n);
    45      }
    46    
    47 return 0;
    48 }
  • 相关阅读:
    sqoop导出数据
    sqoop导入数据
    Hive学习(二)
    各个版本的集群安装包地址
    Hive学习(一)
    数据仓库
    HBase学习(二)
    HBase学习(一)
    MySQL中阻塞
    MySQL中锁问题
  • 原文地址:https://www.cnblogs.com/fenhong/p/4680263.html
Copyright © 2020-2023  润新知