add a base complete quiz 2 cpp code

This commit is contained in:
A.C.Sukazyo Eyre 2022-10-26 22:28:42 +08:00
commit 2086ed0d03
Signed by: Eyre_S
GPG Key ID: C17CE40291207874
2 changed files with 62 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.vscode
**/outfile.txt
**/a.out

58
prob2/quiz2.cpp Normal file
View File

@ -0,0 +1,58 @@
#include <iostream>
struct stack {
int obj[6] = {0, 0, 0, 0, 0, 0};
int next = 0;
int out[6] = {0, 0, 0, 0, 0, 0};
int out_next = 0;
};
void out (stack s) {
std::cout << "{ ";
for (int i = 0; i < s.next; i++) std::cout << s.obj[i] << " ";
std::cout << "// ";
for (int i = 0; i < s.out_next; i++) std::cout << s.out[i] << " ";
std::cout << "}" << std::endl;
}
void loop (stack s, int next) {
if (s.out_next == 6) {
for (int i = 0; i < s.out_next; i++) std::cout << s.out[i] << " ";
std::cout << std::endl;
return;
}
if (next < 7) {
stack sn = stack(s);
sn.obj[sn.next] = next;
sn.next++;
// std::cout << "[DBUG] way IN" << std::endl;
// std::cout << "[DBUG][RA]" << s.out_next << std::endl;
// std::cout << "[DBUG][XM]"; out(sn);
loop(sn, next+1);
}
if (s.next != 0) {
stack sb = stack(s);
sb.out[sb.out_next] = sb.obj[sb.next-1];
sb.obj[sb.next-1] = 0;
sb.next--;
sb.out_next++;
// std::cout << "[DBUG] way OUT" << std::endl;
// std::cout << "[DBUG][RA]" << s.out_next << std::endl;
// std::cout << "[DBUG][XM]"; out(sb);
loop(sb, next);
}
}
int main () {
loop (stack(), 1);
std::cout << "over" << std::endl;
return 0;
}