除法(Division,UVa 725)

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


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值