/*
题目大意:输入正整数n,按从小到大的顺序输出所有形如abcde/fghij = n
的表达式,其中a~j恰好为数字0~9的一个排列,要有前导零
如果不存在输入There are no solutions for n
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char com[13] = "0123456789";//用来判断除数和被除数其中的全部数字是否为0~9的不同数字
char buf[13];
int main(void)
{
int n, i, j;
int k = 0;//控制格式
while (scanf("%d", &n) != EOF && n)
{
bool ok = true;
if (k++)//控制格式
putchar('\n');
for (i = 1234; (j = i * n) < 100000; i++)
{//最小的不相同的数字是01234最大的不相同数字是98765
if (i < 10000)//如果i<10000要在前面补零
sprintf(buf, "0%d%d", i, j);
else//否则不需要补零
sprintf(buf, "%d%d", i, j);
sort(buf, buf + 10);//对这个buf从小大到排序
if (!strcmp(buf, com))//如果buf排序之后和com一样
{
printf("%05d / %05d = %d\n", j, i, n);//那就输出这个算式
ok = false;//如果存在一个那就打标记
}
}
if (ok)//如果没有一个符合条件的就输出这个
printf("There are no solutions for %d.\n", n);
}
return 0;
}
UVA - 725 - Division
最新推荐文章于 2019-10-06 21:19:57 发布