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++实现JNI接口需要注意的事项
- 关于指针的一些事情
- c++ primer 第五版 笔记前言
- share_ptr的几个注意点
- Lua教程(一):在C++中嵌入Lua脚本
- Lua教程(二):C++和Lua相互传递数据示例
- C++联合体转换成C#结构的实现方法
- C++编写简单的打靶游戏
- C++变位词问题分析
- C/C++数据对齐详细解析
- C++基于栈实现铁轨问题
- C++中引用的使用总结
- C++中调用Lua函数实例
- Lua和C++的通信流程代码实例
- C与C++之间相互调用实例方法讲解
- C++中拷贝构造函数的应用详解
- C++中引用(&)的用法与应用实例分析
- C++使用CriticalSection实现线程同步实例
- C++智能指针实例详解
- 解析C++ 浮点数的格式化输出