zoukankan      html  css  js  c++  java
  • Division

    Description

    Download as PDF
     

    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"
    using namespace std;
    
    int n;
    int book[100]= {0};
    
    bool judge(int c,int cc,int ccc)
    {
        memset(book,0,sizeof(book));
        if(ccc==0) book[0]++;
        int t,f;
        t=c;
        f=0;
        while(t/10>0)
        {
            book[t%10]++;
            if(book[t%10]>1)
            {
                f=1;
            }
            t/=10;
        }
        book[t]++;
        if(book[t]>1)
        {
            f=1;
        }
        t=cc;
        while(t/10>0)
        {
            book[t%10]++;
            if(book[t%10]>1)
            {
                f=1;
            }
            t/=10;
        }
        book[t]++;
        if(book[t]>1)
        {
            f=1;
        }
        if(f) return false;
        return true;
    }
    
    
    
    
    void go()
    {
    
        int i,flag;
        flag=0;
        for(i=1111; i<=99999; i++)
        {
            if(i*n>98765) break;
            if(judge(i,i*n,1))
            {
                if((i*n)/10000==0) continue;
                if(i/10000==0&&judge(i,i*n,0))
                {
                    cout<<i*n<<" / 0"<<i<<" = "<<n<<endl;
                    flag=1;
                }
                if(judge(i,i*n,1)&&i/10000!=0)
                {
                    cout<<i*n<<" / "<<i<<" = "<<n<<endl;
                    flag=1;
                }
    
            }
        }
        if(flag==0) cout<<"There are no solutions for "<<n<<'.'<<endl;
    }
    
    
    int main()
    {
        int x=1;
        while(cin>>n&&n)
        {
            if(x>1)   cout<<endl;
            x++;
            go();
    
        }
        return 0;
    }
  • 相关阅读:
    挂载镜像光盘
    源码安装三部曲
    yum和rpm工具使用
    查看软件 有哪些文件
    国内软件源地址
    python代码中碰到的问题及解决 凯
    python之编写登陆接口(第一天) 凯
    python学习笔记之基础二(第二天) 凯
    python学习笔记之基础一(第一天) 凯
    window7下安装第三方包报错及解决 凯
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/4680079.html
Copyright © 2011-2022 走看看