题目链接:https://vjudge.net/contest/147561#problem/A

题意:除法运算,abcde / fghij = n,从小到大输出,其中abcdefghij为0~9的不重复数字。

分析:

1、从小到大其实就是一大就跟着大。

2、不用枚举0~9的全排列,只用枚举其中一个数fghij即可,算出abcde,看是不是0~9都有。

Tip: sprintf(*,格式输入,*);用法,把目标数据转成char * 型。

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     //freopen("in.txt","r",stdin);
 8     int n;
 9     int kase = 0;
10     while(scanf("%d",&n),n)
11     {
12         if(kase++)
13             puts("");
14         int cnt = 0;
15         char buf[99];
16         for(int fghij=1234;; fghij++)
17         {
18             int abcde = fghij*n;
19             sprintf(buf,"%05d%05d",abcde,fghij);
20             if(strlen(buf)>10) break;
21             sort(buf,buf+10);
22 
23             bool flag = true;
24             for(int i=0; i<10; i++)
25                 if(buf[i]!=i+'0')
26                 {
27                     flag = false;
28                     break;
29                 }
30 
31             if(flag)
32             {
33                 cnt ++;
34                 printf("%05d / %05d = %d\n",abcde,fghij,n);
35             }
36 
37         }
38 
39         if(cnt==0)
40             printf("There are no solutions for %d.\n",n);
41     }
42     return 0;
43 }
View Code

相关文章:

  • 2021-11-29
  • 2021-10-23
  • 2019-01-22
  • 2021-12-13
  • 2021-11-13
  • 2022-02-07
  • 2021-11-17
  • 2021-05-23
猜你喜欢
  • 2022-12-23
  • 2021-04-26
  • 2021-07-24
  • 2021-11-25
  • 2021-12-10
  • 2021-09-18
  • 2021-11-01
相关资源
相似解决方案