Division

来源:互联网 发布:js无法删除cookie 编辑:程序博客网 时间:2024/04/29 21:40
A - Division
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
Submit Status

Description

Download as PDF

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\le 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 

61620

Sample Output 

There are no solutions for 61.79546 / 01283 = 6294736 / 01528 = 62
   好坑的格式,竟然/和=两边还有空格。。。
AC代码:
#include <iostream>#include <cstring>#include <cstdio>using namespace std;int n,a[11],f;int jugde(int t){a[t/10000]++;a[t/1000%10]++;a[t%1000/100]++;a[t%100/10]++;a[t%10]++;for(int i=0;i<10;++i){if (a[i]>1){return 0;}}return 1;}int main(){int cnt=0;while (scanf("%d",&n)&&n){f=1;if(cnt++)printf("\n");for (int i=1234;i*n<=98765;++i){memset(a,0,sizeof(a));if (jugde(i)&&jugde(i*n)){f=0;if(i/10000){  printf("%d / %d = %d\n",i*n,i,n);}else{ printf("%d / 0%d = %d\n",i*n,i,n);}}}if(f)printf("There are no solutions for %d.\n",n);}return 0;}


0 0
原创粉丝点击