您的位置:首页 > 编程语言 > C语言/C++

Division

2015-06-20 23:19 1001 查看
A - DivisionTime Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld& %lluSubmit StatusDescriptionWrite 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 secondis equal to an integer N, where . That is,abcde / fghij =Nwhere 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 =Nxxxxx / 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
0

Sample Output 

There are no solutions for 61.

79546 / 01283 = 62
94736 / 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;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++