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;
    }
  • 相关阅读:
    hdu 1593 find a way to escape
    bzoj4561: [JLoi2016]圆的异或并
    hdu 3511 Prison Break
    hdu 5299 Circles Game
    ORA-15025: could not open disk "/dev/asm***"--转载
    修改目的端trail文件的最大大小--转载
    MYSQL PERFORMANCE_SCHEMA HINTS
    Oracle 收缩表大小 Oracle Shrink Table --转载
    InnoDB: Error number 24 means ‘Too many open files’.--转载
    使用asmcmdcp命令把datafile从文件系统移动(move)到asm磁盘组中 针对11gR2
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/4680079.html
Copyright © 2011-2022 走看看