include iostream include vector include string include unordered_set u

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
using namespace std;
vector <char> abc(4, 0);
int i = 0;
void gen (char A, char B, char C, int n) {
if (n > 0) {
gen (A, C, B, n - 1);
cout << abc[1] << abc[2] << abc[3] << " " << ++i << endl;
for (int i = 1; i < 4; ++i) {
if (abc[i] == A) {
abc[i] = B;
break;
}
}
//cout << n << " " << A << " " << B << endl;
gen (C, B, A, n - 1);
}
}
int main () {
/*freopen ("input.txt", "r", stdin);
freopen ("output.txt", "w", stdout);*/
abc[1] = 'A', abc[2] = 'A', abc[3] = 'A';
int n;
cin >> n;
char A = 'A', B = 'B', C = 'C';
string input;
cin >> input;
//A = input[0], B = input[1], C = input[2];
gen (A, B, C, n);
cout << abc[1] << abc[2] << abc[3] << endl;
system ("pause");
return 0;
}