UVA 725 Division (Violent enumeration)

Source: Internet
Author: User

UVA 725 Division


Write a program, finds and displays all pairs of 5-digit numbers, between them use the digits0 through 9 once each, such the first number divided by the second are equal to an integer N, where. That's,


Abcde/fghij = N

Where each letter represents a different digit. The first digit of the numerals is allowed to be zero.

InputEach line of the input file consists of a valid integer N. An input of zero was to terminate the program.OutputYour program has to display all qualifying pairs of numerals, sorted by increasing numerator (and, of course, denominator ).

Your output should is in the following general form:


xxxxx/xxxxx = N

xxxxx/xxxxx = N

.

.


In case there is no pairs of numerals satisfying the condition, you must write 'there is no solutionsforN .". Separate the output for both different values of N by a blank line.

Sample Input
61620
Sample Output
There is no solutions for 61.79546/01283 = 6294736/01528 = 62


The main idea: 0~9 10 numbers make up two 5 digits (or four digits beginning with 0), requiring the quotient of two numbers equal to the input data N.

problem-solving ideas: Violence enumerates all situations and then determines whether they are established.



#include <stdio.h>int number[15];int Check (int a, int b) {if (a > 98765) return 0;  for (int i = 0; i < i++) {Number[i] = 0;  } if (b < 10000) number[0] = 1;  while (a) {  number[a%] = 1;  a/=;  }  while (b) {  number[b%] = 1;  b/=;  }  int sum = 0;  for (int i = 0; i < i++)  sum + = Number[i];  return sum = = ten;  } int main () {int ans, cnt = 0;while (scanf ("%d", &ans) = = 1, ans) {if (cnt++) printf ("\ n"); int flag = 0;for (int i = 12 34; i < 99999; i++) {if (check (i * ans, i)) {printf ("%05d/%05d =%d\n", I * ans, I, ans); flag = 1;}} if (!flag) {printf ("There is no solutions for%d.\n", ans);}} return 0;}




UVA 725 Division (Violent enumeration)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.