zoukankan      html  css  js  c++  java
  • UVA OJ-725 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 2<=N <=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 

    Sample Output 
    There are no solutions for 61.

    79546 / 01283 = 62 
    94736 / 01528 = 62

    译文为:

    写一个程序,查找并显示所有对5位数字,它们之间用数字0 9一次通过,这样第一个数除以二等于一个整数n,其中2<=n≤79。这是,
    ABCDE / fghij = N
    每个字母代表不同的数字。一个数字的第一个数字被允许为零。
    输入
    输入文件的每一行由一个有效的整数N组成,输入的零是终止程序。
    输出
    你的程序要显示所有符合资格的双数字,通过增加分子排序(和,当然,分母)。
    你的输出应该是以下的一般形式:
    xxxxx / xxxxx = N
    xxxxx / xxxxx = N


    如果没有对满足条件的数字,你必须写“没有解决方案为n”。用一条空白线将输出的2个不同的值分别为2个不同的值。
    样本输入
    61
    62
    0
    示例输出
    There are no solutions for 61.


    79546 / 01283 = 62
    94736 / 01528 = 62

    链接http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35442

     1 #include<stdio.h>
     2 #include<string.h>
     3 int a[10];//标记数组 
     4 int check(int x, int y) {
     5   if (y > 98765) return 0;//如果x>98765,肯定有重复的数字 
     6   memset(a, 0, sizeof(a));//标记数组归零 
     7   if (x < 10000) a[0] = 1;//四位数是,第一位为0 
     8   while (x) {//标记x的每位数 
     9     a[x%10] = 1;
    10     x /= 10;
    11   }
    12   while (y) {
    13     a[y%10] = 1;
    14     y /= 10;
    15   }
    16   int sum = 0;
    17   for (int i = 0; i < 10; i++)
    18     if (a[i]) sum++;// 判断0-9数字是否全部用到 
    19   return (sum == 10); 
    20 } 
    21 int main() {
    22   int n, count = 0;
    23   while (scanf("%d", &n) && n) {
    24     int flag = 1;//
    25     if (count++) printf("
    ");//输出格式要求 
    26     for (int i = 1234; i < 100000; i++) {//小与1234必有重复数字,暴力枚举 
    27       if (check(i, i*n)) {//
    28         printf("%05d / %05d = %d
    ", i*n, i, n);//输出格式 
    29         flag = 0;
    30       }
    31     }
    32     if (flag)//
    33       printf("There are no solutions for %d.
    ", n);//注意这里有个"." 
    34   } 
    35 }
  • 相关阅读:
    EasyUI datagrid在insertRow时如果有formatter会出现EasyUI TypeError: rowData.assertEntity is undefined
    序列化与反序列化问题
    序列化和反序列化问题
    Java与.NET的WebServices相互调用
    嫁给程序员吧!!!
    五年之痒
    用户体验5大要素
    敏捷软件开发
    云计算风险识别
    Cute Editor for .NET v6.4
  • 原文地址:https://www.cnblogs.com/Rhett-Q/p/5448488.html
Copyright © 2011-2022 走看看