Professional Documents
Culture Documents
河內塔程式碼
河內塔程式碼
#include<stack>
#include <stdio.h>
#include <string>
using namespace std;
#include<windows.h>
COORD coord;
HANDLE ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
#define x coord.X
#define y coord.Y
#define set SetConsoleCursorPosition(ConsoleHandle,coord)
void build_tower(int n) {
int i = 0;
x = i * n;
y = n - 1;
set;
cout << " ";
for (; i < 3; i++) {
for (int j = 0; j < 2 * n; j++)
cout << "-";
cout << " ";
}
for (int i = 0; i < n; i++) {
x = 1 + i; y = n - i; set;
for (int j = 0; j < n - i; j++)
cout << "一";
}
x = n; y = n + 2; set;
cout << "A";
x = 3 * n + 2; set;
cout << "B";
x = 5 * n + 4; set;
cout << "C";
Sleep(500);
}
int main() {
while (true) {
cout << " _______
河" << endl;
cout << " / \\
" << endl;
cout << " / _ _ \\
" << endl;
cout << " | / \\ / \\
| 內" << endl;
cout << " | _______ |
" << endl;
cout << " \\ \\_____/ /
" << endl;
cout << " \\_______/
塔" << endl;
std::cout << endl<<"輸入 enter 開始遊戲";
std::string temp;
std::getline(std::cin, temp);
cout << "請輸入樓層數:";
int n = 0;
cin >> n;
build_tower(n);
stack <int> A, B, C;