Algorithm improves Ruanxiao Er lottery
Time limit: 1.0s Memory Limit: 512.0MB
Description of the problem
in the students' help, Ruanxiao Er is becoming more and more lazy, and even afterwards do not want to own hands, the daily job is to sit in front of the computer to see if your bank account has changed more than money . But for some down time to observe, Ruanxiao Er found himself account money grow Hao Mana, encounter holidays when even a copper did not enter, even more depressing is that these days no money into even, hateful these banks there may be days, "adding insult to injury" (withholding personal income tax), watching their own money to accounts of negative growth, the Ruanxiao Er, there is the feeling of flesh (too painful!), then Ruanxiao Er greatest wish is undoubtedly the fastest Rijindoujin, what methods can be Rijindoujin it? Bank robbery (line of work)? No, too dangerous, afraid to spend like mad grab life; maintain the status quo? I can not stand, hug money too slow! After much deliberation, after scratching his head, and finally thought of getting rich quick magic ---- buy lottery tickets, spend a life not only made money, good luck, he may be in a few million a day, would not cool zai ! With this in mind, Ruanxiao Er lottery began his journey. The idea is "good" (OR naive stupid), but they found their math skills too bad, because they do not know what combination of numbers has arranged? I now ask someone to write a recursive program that helps Ruanxiao Er solve this problem!
Input format
no more than 6 digit positive integer N, Note: The figures constitute a positive integer N may be repeated
Output Format
composition full permutation of all integer N number of bits, the output in ascending order, each arranged in one row.
Note: the output data can not be duplicated arrangement
Sample input
123
Sample Output
123
132
213
231
312
321
Sample input
3121
Sample Output
1123
1132
1213
1231
1312
1321
2113
2131
2311
3112
3121
3211
Sample input
4003
Sample Output
0034
0043
0304
0340
0403
0430
3004
3040
3400
4003
4030
4300
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
string N;
cin >> N;
sort(N.begin(), N.end());
cout << N << endl;
while (next_permutation(N.begin(), N.end()))
cout << N << endl;
return 0;
}