UVa 725 Division

#Algorithm
枚举
#Hint
文件末尾不能有空行
#Code

#include <cstring>
#include <iostream>
using namespace std;
int n;
bool flag;
bool b[10];
void solve()
{
  flag = false;
  for (int f = 0; f < 10; f++)
  for (int g = 0; g < 10; g++)
  for (int h = 0; h < 10; h++)
  for (int i = 0; i < 10; i++)
  for (int j = 0; j < 10; j++)
  {
    memset(b, 0, sizeof(b));
    b[f] = true;
    if (b[g]) continue; b[g] = true;
    if (b[h]) continue; b[h] = true;
    if (b[i]) continue; b[i] = true;
    if (b[j]) continue; b[j] = true;
    long long abcde = n * (f * 10000 + g * 1000 + h * 100 + i * 10 + j);
    if (abcde > 99999) continue;
    int a = abcde / 10000; abcde %= 10000;
    if (b[a]) continue; b[a] = true;
    int bb = abcde / 1000; abcde %= 1000;
    if (b[bb]) continue; b[bb] = true;
    int c = abcde / 100; abcde %= 100;
    if (b[c]) continue; b[c] = true;
    int d = abcde / 10; abcde %= 10;
    if (b[d]) continue; b[d] = true;
    int e = abcde;
    if (b[e]) continue;
    cout << a << bb << c << d << e << " / " << f << g << h << i << j << " = " << n << endl;
    flag = true;
  }
  if (!flag) cout << "There are no solutions for " << n << "." << endl;
}
int main()
{
  cin >> n;
  if (n == 0) return 0;
  solve();
  for (;;)
  {
    cin >> n;
    if (n == 0) break;
    cout << endl;
    solve();
  }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值