您的位置:首页 > 其它

除法(Division,UVa 725)

2015-11-08 15:41 447 查看
题意:输入正整数n,按从小到大的顺序输出所有形如abcde/fghij = n的表达式,其中a-j敲好位数字0-9的全排列(可以有前导0),2 <= n <= 79。



思路:枚举abcde,由n算出fghij,进而判断是否满足题意即可。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<string>
#include<map>
#include<sstream>
#include<queue>
#include<cctype>
using namespace std;
#define MAX 17
typedef long long ll;
int p[11];
bool get(int x) {
int exp = 10000;
while(exp) {
int m = (x / exp) % 10;
exp /= 10;
if(p[m]) return false;
p[m]++;
}
return true;
}
int main() {
int n;
bool flag;
bool first = true;
while(~scanf("%d",&n) && n) {
if(first)
first = false;
else
printf("\n");
flag = true;
for(int i=1000;i<98766;i++) {
memset(p,0,sizeof(p));
if(get(i) && i % n == 0)
if(get(i/n)) {
flag =false;
printf("%05d / %05d = %d\n",i,i/n,n);
}
}
if(flag) {
printf("There are no solutions for %d.\n",n);
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: