zoukankan      html  css  js  c++  java
  • UVA

      Division 

    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 $2le 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 <bits/stdc++.h>
    using namespace std;
    
    bool is_ok(int a, int b, int c, int d, int e, int res)
    {
        if(res > 99999 || res<10000)
            return false;
        bool check[10] = {false};
        check[a] = check[b] = check[c] = check[d] = check[e] = true;
        while(res > 0)
        {
            check[res%10] = true;
            res /= 10;
        }
        for(int i = 0; i <= 9; i++)
            if(check[i] == false)
                return false;
        return true;
    }
    
    int main()
    {
        int n;
        bool firstline = true;
        while(scanf("%d", &n), n != 0)
        {
            if(firstline)  firstline = false;
            else  printf("
    ");
            bool flag = false;
            int a, b, c, d, e, x, res;
            for(a = 0; a <= 9; a++)
                for(b = 0; b <= 9; b++)
                    for(c = 0; c <= 9; c++)
                        for(d = 0; d <= 9; d++)
                            for(e = 0; e <= 9; e++){
                                x = a*10000 + b*1000 + c*100 + d*10 + e;
                                res = x * n;
                                if(is_ok(a, b, c, d, e, res)){
                                    printf("%d / %d%d%d%d%d = %d
    ", res, a, b, c, d, e, n);
                                    flag = true;
                                }
                            }
            if(!flag)
                printf("There are no solutions for %d.
    ", n);
        }
        return 0;
    }


  • 相关阅读:
    正则表达式
    浏览器加载时间线
    浏览器事件
    脚本化CSS
    定时器元素大小位置属性等 20181231
    关于行内元素 20181229
    个人冲刺01
    周总结
    团队冲刺10
    团队冲刺09
  • 原文地址:https://www.cnblogs.com/kunsoft/p/5312774.html
Copyright © 2011-2022 走看看