UVA 725
sprintf(buf, "%05d%05d", abcde, fghij);
0补位,避免153078 / 02469 = 62数据出现。
153078 / 02469 = 62中,153078 / 2469 = 62,由于没有补位,也整好满足相除等于62且从0到9
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n ;
char buf[20];
while(scanf("%d", &n) == 1 && n)
{
int cnt = 0;
for(int fghij = 1234; ; fghij++)
{
int abcde = fghij * n;
sprintf(buf, "%05d%05d", abcde, fghij);
// sprintf(buf, "%d%d", abcde, fghij);
if(strlen(buf) > 10) break;
sort(buf, buf+10);
bool ok = true;
for(int i = 0; i < 10; i++)
if(buf[i] != '0' + i) ok = false;
if(ok)
{
cnt++;
printf("%05d / %05d = %d
", abcde, fghij, n);
}
}
if(!cnt) printf("There are no solutions for %d.
", n);
}
return 0;
}