Welcome

首页 / 软件开发 / 数据结构与算法 / UVa 471 Magic Numbers:枚举

UVa 471 Magic Numbers:枚举2014-07-07 csdn博客 synapse7http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=412

直接枚举。代码中给出了一个用位运算判断数字中是否有重复数字的方法。

完整代码:

01./*0.032s*/02.03.#include <cstdio>04.const long long maxn = 9876543210LL;05.06.inline bool check(long long n)07.{08.int i, cnt = 0;09.while (n)10.{11.i = 1 << (n % 10);12.if (cnt & i) return false;13.cnt |= i;14.n /= 10;15.}16.return true;17.}18.19.int main()20.{21.long long s1, s2, n;22.int t;23.scanf("%d", &t);24.while (t--)25.{26.scanf("%lld", &n);27.for (s2 = 1; s2 <= maxn; ++s2)28.{29.s1 = n * s2;30.if (s1 > maxn) break;31.if (check(s2) && check(s1)) printf("%lld / %lld = %lld
", s1, s2, n);32.}33.if (t) putchar(10);34.}35.return 0;36.}