Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by duc ( 3 years ago )
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
int n, ok;
int x[100];
vector <string> v;
int a[100];
char chu[50];
void chu_cai(){
for (int i = 1; i<= 26;i++){
chu[i] = 'A' - 1 + i;
}
}
void ktao_hoan_vi(){
for (int i = 1 ; i <= n;i++){
x[i] = i;
}
}
void ktao_so(){
for (int i = 1; i<= n;i++){
a[i] = 1;
}
}
void init(){
chu_cai();
ktao_hoan_vi();
do{
string tmp = "";
for (int i = 1; i <= n;i++){
tmp += chu[x[i]];
}
v.push_back(tmp);
}while (next_permutation(x + 1, x + n + 1));
}
void sinh_so(){
int i = n;
while (i > 0 && a[i] == n){
i--;
}
if (i == 0) ok = 0;
else{
a[i]++;
for (int j = i + 1;j <= n;j++){
a[j] = 1;
}
}
}
int main(){
cin >> n;
init();
// for (string x : v) cout << x << endl;
// cout <<"-----------------" << endl;
for (string x : v){
ok = 1;
ktao_so();
while (ok){
cout << x;
for (int i = 1; i<=n;i++){
cout << a[i];
}
cout << endl;
sinh_so();
}
}
return 0;
}
Revise this Paste
Parent: 124611