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;
    }


  • 相关阅读:
    阿里云盾证书服务助力博客装逼成功
    内容安全策略(CSP)_防御_XSS_攻击的好助手
    Spring-beans架构设计原理
    Httpclient核心架构设计
    第四章 数据类型—字典(dict)、集合(set)
    第三章 数据类型 — 列表(list)、元组(tuple)
    第三章 数据类型 — int、bool 和 str
    第二章 Python基础(二)
    pycharm快捷键
    第二章 Python基础(一)
  • 原文地址:https://www.cnblogs.com/kunsoft/p/5312774.html
Copyright © 2011-2022 走看看