UVA - 725(水题)
来源:互联网 发布:linux系统模拟下载 编辑:程序博客网 时间:2024/04/30 17:13
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 ≤ N ≤ 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
61
62
0
Sample Output
There are no solutions for 61.
79546 / 01283 = 62
94736 / 01528 = 62
水题直接上代码
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <map>#include <queue>#include <cmath>using namespace std;int main(){ int n, a[10], first = 1; while (scanf ("%d", &n) != EOF) { if (n == 0) break; if (first) { first = 0; } else { printf ("\n"); } int num1 = 1, num2 = 1; int side = 98765 / n; int flag1 = 0; for (num1 = 1234; num1 <= side; num1++) { int flag = 1; num2 = num1 * n; a[0] = num2 / 10000; a[1] = num2 / 1000 % 10; a[2] = num2 / 100 % 10; a[3] = num2 / 10 % 10; a[4] = num2 % 10; a[5] = num1 / 10000; a[6] = num1 / 1000 % 10; a[7] = num1 / 100 % 10; a[8] = num1 /10 % 10; a[9] = num1 % 10; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (j != i && a[i] == a[j]) { flag = 0; } } } if (flag) { printf ("%d%d%d%d%d / %d%d%d%d%d = %d\n", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9], n); flag1 = 1; } } if (flag1 == 0) { printf ("There are no solutions for %d.\n", n); } } return 0;}
- UVA - 725(水题)
- UVa 725:Division(水题)
- uva 11461(水题)
- UVA Ants(水题)
- UVA UVa 272 水题
- UVa 725 Division(枚举)
- 除法(division,UVa 725)
- 除法(Division,UVa 725)
- UVa 725 Division(除法)
- UVa--725 Division(枚举)
- Uva 725 Division(暴力)
- 例题:除法(UVa 725)
- UVa 725 Division(除法)
- UVA 654 Ratio(水题)
- Symmetry UVa 1595(水题)
- 水题(决斗,uva 1636)
- uva 725 division(水题)——yhx
- uva 725 division(水题)——yhx
- As新建一个module形式的第三方library
- 快速选择
- 深入理解javascript的作用域--函数声明为什么会前置
- jdk的配置
- Ubuntu下让Linux开发板通过笔记本上网
- UVA - 725(水题)
- 数据结构之二叉树
- 动态SQL与模糊查询
- 使用Hive编写MapReduce程序
- Ubuntu 安装JDK1.8
- Eclipse下配置git方法
- vmware harbor源码编译
- 梳理struts2-执行原理
- iOS多线程