UVA 725 Division
来源:互联网 发布:非农就业数据公布 编辑:程序博客网 时间:2024/05/18 10:33
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 =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 =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
题意
给出一个公式 abcde/fghij=n.输入n,输出abcde/fghij=n。当输入0时,循环结束;
代码实现
#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <cstring>using namespace std;int _list[10]; //存储abcdefghij的数值bool ok(int x, int y){ memset (_list, 0, sizeof (_list));//初始化为0 for (int i=1; i<=5; ++i) { _list[x%10]++; _list[y%10]++; if (_list[x%10] > 1 || _list[y%10] > 1) return 0; x /= 10; y /= 10; } return true;} int main() { int N, cnt = 0; while (scanf ("%d", &N) == 1) { if (N == 0) break; if (cnt++) puts (""); int one = 0; for (int i=1234; i<=100000/N; ++i) { if (i * N > 98765) //abcde最大值为98765 break; if (ok (i, i*N) == true)//用ok()函数进行判断 { printf ("%05d / %05d = %d\n", N*i, i,N ); one++; } } if (!one) printf ("There are no solutions for %d.\n", N); } return 0;}
- UVA 725 - Division
- UVA 725 - Division
- UVa 725 - Division
- UVA - 725 Division
- UVa 725 - Division
- UVa 725 Division
- UVa 725 - Division
- Uva 725 Division
- UVA-725除法-Division
- UVA - 725 Division
- uva 725 - Division
- Uva - 725 - Division
- UVA - 725 Division
- uva 725 Division
- 除法(Division, UVa 725)
- UVA 725 Division
- UVA 725 - Division
- UVa 725----Division(枚举)
- SVD奇异值分解
- NYOJ 55 懒省事的小明(简单优先队列)
- Shiro权限框架
- 程序员学英语--毕业后的第一个月
- Mysql temporary table
- UVA 725 Division
- Qt发布Release版本注意事项
- 西天取经后续
- ios 判断字符串中是否包含中文
- LeetCode题解——Sort List
- 坑爹的BOM PHP
- THE DRUNK JAILER(POJ--1218
- 题目 H
- #import,#include,@class