zoukankan      html  css  js  c++  java
  • UVA725 Division 除法【暴力】

    题目链接>>>>>>

    题目大意:
    给你一个数n(2 <= n <= 79),将0-9这十个数字分成两组组成两个5位数a, b(可以包含前导0,如02345也算),使得a / b = n;列出所有的可能答案。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <cmath>
    
    using namespace std;
    
    int main()
    {
        int n, a[10], first = 1;
        while (scanf("%d", &n) != EOF,n) {
            if (first) {
                first = 0;
            }
            else {
                printf("
    ");
            }                                //以上是两组数据之间输出空行的技巧
            int num1 = 1, num2 = 1;
            int side = 98765 / n;           //这里稍微降低了一下复杂度
            int flag1 = 0;
            for (num1 = 1234; num1 <= side; num1++) {
                int flag = 1;
                num2 = num1 * n;
                a[0] = num2 / 10000;
                a[1] = num2 / 1000 % 10;
                a[2] = num2 / 100 % 10;
                a[3] = num2 / 10 % 10;
                a[4] = num2 % 10;
                a[5] = num1 / 10000;
                a[6] = num1 / 1000 % 10;
                a[7] = num1 / 100 % 10;
                a[8] = num1 / 10 % 10;
                a[9] = num1 % 10;
                for (int i = 0; i < 10; i++) {
                    for (int j = 0; j < 10; j++) {
                        if (j != i && a[i] == a[j]) {            //这里判断10位数是否有重复的方法
                            flag = 0;
                        }
                    }
                }
                if (flag) {
                    for (int i = 0; i < 5; i++)cout << a[i]; cout << " / ";                        //注意这里"/"和"="左右两边都有空格
                    for (int i = 5; i < 10; i++)cout << a[i]; cout << " = " << n << endl;
                    flag1 = 1;
                }
            }
            if (flag1 == 0) {
                printf("There are no solutions for %d.
    ", n);
            }
        }
        return 0;
    }

    2018-04-08

  • 相关阅读:

    删与改

    基本操作
    名词解释
    Python内置函数(11)——complex
    Python内置函数(10)——float
    Python内置函数(9)——int
    Python内置函数(8)——bool
    Python内置函数(7)——sum
  • 原文地址:https://www.cnblogs.com/00isok/p/8748754.html
Copyright © 2011-2022 走看看