Original question:
Description
Write a program, finds and displays all pairs of 5-digit numbers, between them use the digits 0 through C1>9once 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 solutions for N.". 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
My Code:
#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;intMain () {intN, Kase =0; Charbuf[ About]; while(SCANF ("%d", &n) = =1&&N) {intCNT =0; if(kase++) printf ("\ n"); for(intFghij =1234;; fghij++) { intABCDE = Fghij *N; sprintf (BUF,"%05d%05d", ABCDE, FGHIJ); if(strlen (BUF) >Ten) Break; Sort (buf, buf+Ten); BOOLOK =true; for(inti =0; I <Ten; i++) if(Buf[i]! ='0'+ i) OK =false; if(OK) {CNT++; printf ("%05d/%05d =%d\n", ABCDE, FGHIJ, N); } } if(!cnt) printf ("There is no solutions for%d.\n", N); } return 0;}
View Code
UVA 725 Division (violent enumeration) tips for solving problems