HDU1716(next_permutation)

#include
using namespace std;
int main()
{
	int a[4], ok = 0;
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	while (1) {
		if (a[0] + a[1] + a[2] + a[3] == 0) break;
		sort(a, a + 4);
		int k = a[0];
		if (a[0]) cout << a[0] << a[1] << a[2] << a[3];
		while (next_permutation(a, a + 4)) {
			if (a[0] == k && a[0]) cout << " " << a[0] << a[1] << a[2] << a[3];
			else {
				if (a[0]) {
					if (k!=0) cout << endl;
					cout << a[0] << a[1] << a[2] << a[3];
				}
				k = a[0];
			}
		}
		cout << endl;
		cin >> a[0] >> a[1] >> a[2] >> a[3];
		if (a[0] + a[1] + a[2] + a[3] != 0) cout << endl;
	}
	return 0;
}

 

你可能感兴趣的:(HDU1716(next_permutation))