#HDU 1716 (full array)

Problem Description

Ray and columns of numbers generated interest:
conventional four cards, with which the four cards can be arranged in many different four digits required by the order of small to large outputs 4 bits.

 

 

Input

Each set of data per line, represents a number in the four cards (0 <= number <= 9), if the four cards are 0, the input ends.

 

 

Output

For each card in ascending order of the outputs of all four digits can be composed by these four cards, one thousand same numbers in the same row, the same row are separated by spaces between each digit.
Blank line between each set of output data, the data is not the last group back empty row.

 

 

Sample Input

 

1 2 3 4 1 1 2 3 0 1 2 3 0 0 0 0

 

 

Sample Output

 

1234 1243 1324 1342 1423 1432 2134 2143 2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312 4321 1123 1132 1213 1231 1312 1321 2113 2131 2311 3112 3121 3211 1023 1032 1203 1230 1302 1320 2013 2031 2103 2130 2301 2310 3012 3021 3102 3120 3201 3210

 Full array like, if I want to see the source code can be seen directly in this blog function: https://blog.csdn.net/weixin_43851525/article/details/90405738

Key plan: First, pay attention to each sample blank line after the last sample does not need to find an identifier, and if the input does not end on a blank line is not 0; secondly, requires one thousand identical numbers in a row, this As long as three digits after the judgment is not in the reverse order can be a dictionary; final pits, can not put the first 0! ! Because this is the thousand figure, not a string.

 

AC Code:

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 10;

int p[maxn], X;

int main()
{
    while (cin >> p[0] >> p[1] >> p[2] >> p[3]) {
        if (p[0] + p[1] + p[2] + p[3] == 0) break;
        if (X) cout << endl;
        sort (p, p + 4);  //注意排序
        do {
            if (p[0] == 0) continue;
            cout << p[0] << p[1] << p[2] << p[3];
            if (p[1] >= p[2] && p[2] >= p[3]) cout << endl;
            else cout << " ";
        }
        while (next_permutation (p, p + 4));
        X++;
    }
    return 0;
}

 

Guess you like

Origin blog.csdn.net/weixin_43851525/article/details/92205983