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


  • 相关阅读:
    FTP登录 下载上传文件(太过简单暂时未写)
    依据文档批次命名图片
    UDP协议
    tcp协议(三次握手 四次挥手)
    1956年人工智能元年,而今天是我进入人工智能的日子,哈哈哈
    对比文件简易代码
    爬取网站内容,存放到excel中
    Redis-Py 使用
    python list减法
    sort 使用key函数时,赋多个排序参数
  • 原文地址:https://www.cnblogs.com/kunsoft/p/5312774.html
Copyright © 2011-2022 走看看