Home > Back-end >  Newcomer to solve the problem, who teach
Newcomer to solve the problem, who teach

Time:10-09

Please calculate the following problems: the ABCD - EFGH=2016
One ABCD and EFGH represent four digits, in which each letter (A - H) represents 1-9 of which A number, the different letters represent Numbers, please type on calculate how many kind of solution? For example: 4613-2597=2016 is one of the solutions,

CodePudding user response:

# include & lt; stdio.h>

# define the check (x) if (flag [x]) continue; The else flag [x] + +
Int main () {
For (int I=3017; I<9999; I++) {
Int flag [10]={0};
Int a, b, c, d;
Int t=I;
D=t % 10; t/=10; Check (d);
C=t % 10; t/=10; Check (c);
B=t % 10; t/=10; Check (b);
A=t; Check (a);
T=I - 2016;
Int e, f, g, h;
H=t % 10; t/=10; Check (h);
G=t % 10; t/=10; Check (g);
F=t % 10; t/=10; Check (f);
E=t; Check (e);
Printf (" % d, % d=2016 \ n ", I, I - 2016);
}
return 0;
}

3502-1486=2016
3508-1492=2016
3608-1592=2016
3705-1689=2016
3708-1692=2016
4603-2587=2016
4607-2591=2016
4613-2597=2016
4701-2685=2016
4705-2689=2016
5708-3692=2016
5710-3694=2016
5714-3698=2016
5810-3794=2016
5812-3796=2016
6203-4187=2016
6205-4189=2016
6301-4285=2016
6305-4289=2016
6307-4291=2016
7310-5294=2016
7314-5298=2016
7402-5386=2016
7408-5392=2016
7412-5396=2016
8307-6291=2016
8310-6294=2016
8407-6391=2016
8507-6491=2016
8513-6497=2016
9301-7285=2016
9401-7385=2016
9402-7386=2016
9502-7486=2016

CodePudding user response:

# include & lt; stdio.h>
Int main () {
Int nCount=0;
For (int I=3017; I<9999; I++) {
Int flag [10]={0};
Int t=I * 10000 + l (I - 2016);
Int j=0, v=0;
For (; j<8; J++) {
V=t % 10;
If (flag [v]) break; The else flag [v] + +;
T/=10;
}
If (j!=8) continue;
NCount + +;
Printf (" % d, % d=2016 \ n ", I, I - 2016);
}
Printf (" \ n \ nTotal: % d ", nCount);
return 0;
}

CodePudding user response:

Fun
reference 2 floor response:
# include & lt; stdio.h>
Int main () {
Int nCount=0;
For (int I=3017; I<9999; I++) {
Int flag [10]={0};
Int t=I * 10000 + l (I - 2016);
Int j=0, v=0;
For (; j<8; J++) {
V=t % 10;
If (flag [v]) break; The else flag [v] + +;
T/=10;
}
If (j!=8) continue;
NCount + +;
Printf (" % d, % d=2016 \ n ", I, I - 2016);
}
Printf (" \ n \ nTotal: % d ", nCount);
return 0;
}

Abcdefgh for 1-9, 0.

CodePudding user response:

 # include 
using namespace std;
Int n, r;
Bool vis [30].
Int a, [30].
Void (pr) {
for(int i=1; I<=r; I++) {
CoutIf (I==4) {
Cout<& lt;" - ";
}
}
Cout<& lt;"=2016 "& lt; }
Void DFS (int x, int num) {
If (num> R) {
If (a * 1000 + [1] [2] a * 100 * 10 + a + a [3] [4], a [5] [6] * 100 * 1000 - a - a [7] [8] * 10 - a==2016) {
Pr ();
}
}
The else {
for(int i=1; I<=n; I++) {
if(! Vis [I]) {
Vis [I]=1;
A [x]=I;
DFS (x + 1, num + 1);
Vis [I]=0;
}
}
}
}
Int main () {
The scanf (" % d % d ", & amp; N, & amp; R);
DFS (1, 1);
return 0;
}

Is a permutation and combination
Enter 9 8
The results for the
4613-2597=2016
5714-3698=2016
5812-3796=2016
7314-5298=2016
7412-5396=2016
8513-6497=2016

CodePudding user response:

Does not contain zero, is also very simple, changed a place can
For (; j<8; J++) {
V=t % 10;
if (0==v) break;
If (flag [v]) break; The else flag [v] + +;
T/=10;
}

The answer is 6
  • Related