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;
    }
  • 相关阅读:
    QT开发之旅一DS7400主机调试工具
    读《程序员,你伤不起》杂感(附带分享两个项目源码)
    这些年过上幸福生活的程序员(中篇)
    这些年过上幸福生活的程序员(上篇)
    如果第三方数据表与系统数据库里的表名格式不一致的解决方案
    数据库设计原则
    MYSQL密码设置
    关于phpmyadmin #1045无法登陆服务器的问题
    TP快捷函数
    跨控制器调用
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/4680079.html
Copyright © 2011-2022 走看看