Division
直接暴力枚举然后判断是否符合题目要求
#include <iostream>
#include <cstring>
using namespace std;
bool st[10];
bool check(int x, int y)
{
//两个数不可能同时都是4位数,上边只可能是5位数,下面才有可能是4位数
//上面是4位数的话,下面必须是5位数,这个分数肯定<1了
if(x < 10000 && y < 10000) return false;
if(x >= 98765 || y >= 98765) return false;//而且最大不会超过98765
memset(st, 0, sizeof st);
for(int i = 0; i < 5; i ++)
{
st[x % 10] = st[y % 10] = true;
x /= 10, y /= 10;
}
for(int i = 0; i < 10; i ++)
if(st[i] == false)
return false;
return true;
}
int main()
{
int n, k = 0;
while(cin >> n && n)
{
if(k ++) puts("");//这里对格式的要求还挺严的
bool f = false;
//枚举下面的数,最小也得是01234,最大不会超过98765
for(int i = 1234; i <= 98765; i ++)
{
int t = i * n;
if(check(i, t)) printf("%05d / %05d = %d\n", t, i, n), f = true;
}
if(!f) printf("There are no solutions for %d.\n", n);
//该说不说这里居然最后还有个"."我是真没看见啊。。。。
}
return 0;
}