UVA - 725 - Division

题目传送门

/*
	题目大意:输入正整数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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值