zoukankan      html  css  js  c++  java
  • uva725(除法)

    Description

    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
    
    题意:
    输入正整数n,按从小到大的顺序输出全部形如abcde/fghij=n的表达式,当中a~j恰好为数字0~9的一个排列(能够有0前导)
    思路:
    枚举fghij就能够算出abcde,然后推断符不符合条件。
    代码:
    #include<cstdio>
    using namespace std;
    int main()
    {
        int i,j,k,l,m,a,b;
        int b1,b2,b3,b4,b5;
        int flag;
        int N;
        int casex=0;
        while(scanf("%d",&N)&&N)
        {
            if(casex++)   printf("
    ");
            flag=0;
          for( i=0;i<=9;i++)
              for(j=0;j<=9;j++)
                for(k=0;k<=9;k++)
                    for(l=0;l<=9;l++)
                        for(m=0;m<=9;m++)
        {
            if(i!=j&&i!=k&&i!=l&&i!=m&&j!=k&&j!=l&&j!=m&&k!=l&&k!=m&&l!=m)
                a=i*10000+j*1000+k*100+l*10+m;
                else continue;
             b=N*a;
             if(b>99999)
                continue;
            b1=b/10000;
            b2=b%10000/1000;
            b3=b%10000%1000/100;
            b4=b%10000%1000%100/10;
            b5=b%10;
            if(b1!=b2&&b1!=b3&&b1!=b4&&b1!=b5&&b2!=b3&&b2!=b4&&b2!=b5&&b3!=b4&&b3!=b5&&b4!=b5&&b1!=i&&b1!=j&&b1!=k&&b1!=l&&b1!=m&&b2!=i&&b2!=j&&b2!=k&&b2!=l&&b2!=m&&b3!=i&&b3!=j&&b3!=k&&b3!=l&&b3!=m&&b4!=i&&b4!=j&&b4!=k&&b4!=l&&b4!=m&&b5!=i&&b5!=j&&b5!=k&&b5!=l&&b5!=m)
            {
              printf("%d / %d%d%d%d%d = %d
    ",b,i,j,k,l,m,N);
              flag=1;
            }
            else
                continue;
    
           }
    
        if(!flag)  printf("There are no solutions for %d.
    ",N);
    
        }
        return 0;
    
    }
    

     



    Miguel Revilla
    2000-08-31
  • 相关阅读:
    Postfix常用命令和邮件队列管理(queue)
    window7下面rabbitMQ安装配置过程详解
    RabbitMQ系列之消息确认机制
    全文检索:sphinx elasticsearch xunsearch 比较
    用SQL命令查看Mysql数据库大小
    部署Percona监控和管理--- PMM Server
    什么是MTU?为什么MTU值普遍都是1500?
    Mysql删除数据后,磁盘空间未释放的解决办法
    数据库索引
    visual studio 容器工具首次加载太慢 vsdbgvs2017u5 exists, deleting 的解决方案
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/6955394.html
Copyright © 2011-2022 走看看