Home > Back-end >  Save the children!
Save the children!

Time:09-16

Is really can't write

CodePudding user response:

For (int k=11; K & lt; 100; K++)
{
For (int I=k + 1; I & lt; 100; I++)
{
For (int j=k + 1; J & lt; 100; J++)
{
If (I * j % k==0 & amp; & I * j/k & gt;=111 & amp; & I * j/k & lt; 1000)
{
Dx dx printf (" % % d=% % d \ n ", I, j, k, I * j/k);
}
}
}
}

CodePudding user response:

The
reference 1/f, 5250 response:
for (int k=11; K & lt; 100; K++)
{
For (int I=k + 1; I & lt; 100; I++)
{
For (int j=k + 1; J & lt; 100; J++)
{
If (I * j % k==0 & amp; & I * j/k & gt;=111 & amp; & I * j/k & lt; 1000)
{
Dx dx printf (" % % d=% % d \ n ", I, j, k, I * j/k);
}
}
}
}

Topic request number does not repeat, this program does not have to decide questions of digital repeated,

CodePudding user response:

This problem can be seen as the Numbers 1 to 9 on a don't repeat the whole arrangement, the key is to try to improve the efficiency of the whole arrangement,
Really don't want to write the program,

CodePudding user response:

Upstairs @ tryagain2006 idea is very high, below is follow his train of thought to do,

I explain:

Make a full arrangement of 1 to 9, thus guarantee the 1-9 are used and used only once,
It is divided into four parts, such as: 123456789, divided into 12, 34, 56, 789,
Check the 12 * 34 and 56 * 789, it is ok to see if they are equal,

So the problem is converted into 1-9 of permutations, check each order, arrangement, and find out to meet the requirements of

The exhaustive cycles is: a total of 9!=362880 times, running very fast,

Permutations using recursive method, draw lessons from the online ready-made algorithms, hereby,

Procedure is as follows:

# include
Void perm (int k, int n, int a []) {
If (k==n - 1) {
Int d1=a [0] * 10 + a, [1].
Int d2=a [2] * 10 + a, [3].
Int d3=a [4] * 10 + a, [5].
Int d4=a [6] * 100 * 10 + a + a [7] [8].
If (d1 * d2==d3 * d4) {
Printf (" % 2 d * * % % 2 d=% 2 d 3 d \ n ", d1, d2, d3, d4);
}
}
The else {
For (int I=k; I & lt; n; I++) {
Int temp=a, [k].
A [k]=a, [I].
A [I]=temp;
Perm (k + 1, n, a);
Temp=a, [k].
A [k]=a, [I].
A [I]=temp;
}
}
}

Int main () {
Int arr [9]={1, 2, 3, 4, 5, 6, 7, 8, 9};
Perm (0, 9, arr);
return 0;
}

The result is:

46 * 23 * 79=158
54 27 * * 69=138
54 27 * * 93=186
58 29 * * 67=134
58 * 23 * 69=174
58 29 * * 73=146
58 * 32 * 96=174
18 * 63 * 74=259
32 * 64 * 79=158
29 * 67 * 58=134
27 * 69 * 54=138
23 * 174 69 * 58=
29 * 73 * 58=146
12 * 73 * 96=584
18 * 74 * 63=259
14 * 76 * 98=532
23 * 158 79 * 46=
32 * 79 * 64=158
27 * 93 * 54=186
58=96 * 32 * 174
12 * 96 * 73=584
14 * 98 * 76=532


CodePudding user response:

If written in Python, you below 9 line to solve the problem, run results,
It's should be that sentence:
"Life is too short, I use Python"
"Life is short, you need Python!"



The from itertools import permutations
A=[1, 2, 3, 4, 5, 6, 7, 8, 9]
For p permutations in (a) :
D1=p [0] * 10 + p [1]
D2=p * 10 + p [2] [3]
D3 * 10 + p=p [4] [5]
D4=p [6] * 100 * 10 + p + p [7] [8]
If d1 * * d2==d3 d4:
Print (d1, "*", d2, "=", d3, "*", d4)

CodePudding user response:

reference 5 floor rrrr336 reply:
upstairs @ tryagain2006 idea is very high, below is the follow his train of thought to do,

I explain:

Make a full arrangement of 1 to 9, thus guarantee the 1-9 are used and used only once,
It is divided into four parts, such as: 123456789, divided into 12, 34, 56, 789,
Check the 12 * 34 and 56 * 789, it is ok to see if they are equal,

So the problem is converted into 1-9 of permutations, check each order, arrangement, and find out to meet the requirements of

The exhaustive cycles is: a total of 9!=362880 times, running very fast,

Permutations using recursive method, draw lessons from the online ready-made algorithms, hereby,

Procedure is as follows:

# include
Void perm (int k, int n, int a []) {
If (k==n - 1) {
Int d1=a [0] * 10 + a, [1].
Int d2=a [2] * 10 + a, [3].
Int d3=a [4] * 10 + a, [5].
Int d4=a [6] * 100 * 10 + a + a [7] [8].
If (d1 * d2==d3 * d4) {
Printf (" % 2 d * * % % 2 d=% 2 d 3 d \ n ", d1, d2, d3, d4);
}
}
The else {
For (int I=k; I & lt; n; I++) {
Int temp=a, [k].
A [k]=a, [I].
A [I]=temp;
Perm (k + 1, n, a);
Temp=a, [k].
A [k]=a, [I].
A [I]=temp;
}
}
}

Int main () {
Int arr [9]={1, 2, 3, 4, 5, 6, 7, 8, 9};
Perm (0, 9, arr);
return 0;
}

The result is:

46 * 23 * 79=158
54 27 * * 69=138
54 27 * * 93=186
58 29 * * 67=134
58 * 23 * 69=174
58 29 * * 73=146
58 * 32 * 96=174
18 * 63 * 74=259
32 * 64 * 79=158
29 * 67 * 58=134
27 * 69 * 54=138
23 * 174 69 * 58=
29 * 73 * 58=146
12 * 73 * 96=584
18 * 74 * 63=259
14 * 76 * 98=532
23 * 158 79 * 46=
32 * 79 * 64=158
27 * 93 * 54=186
58=96 * 32 * 174
12 * 96 * 73=584
14 * 98 * 76=532

Thank?? , I think so too, but I can't write, thanks for bosses

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related