# 【題解】ZeroJudge b190: 97七區資訊學科5(改編)

• 變數定義：
• todo: 未達定位的盤子數目
• doing: 接下來要移動的目標
• times: 目前累積移動的次數
```#include <iostream>
#include <cmath>
using namespace std;

int times, todo, doing;

void move(int now, char start, char target, char between){
if (now > 0){
move(now-1, start, between, target);
cout << "ring " << now << " : " << start << " -> " << target << "\n";
times++;
move(now-1, between, target, start);
}
}

int main(){
int n;
char start, between, target, temp;
while (cin >> n){
times = 0;
todo = n;
doing = n;
start = 'a';
if (n % 2 == 0){
target = 'c';
between = 'b';
}else{
target = 'b';
between = 'c';
}
while (todo > 0){
//move the pile above doing
move(doing-1, start, between, target);
if (doing-1 > 0) todo -= 1;
if (todo == 0) break;

//move doing
cout << "ring " << doing << " : " << start << " -> " << target << "\n";
times++;
todo -= 1;
if (todo == 0) break;

//setting for the second part
doing -= 2;
temp = between;
between = start;
start = temp;

//move second pile (do not todo-=1)
move(doing-1, start, between, target);

//move doing again
cout << "ring " << doing << " : " << start << " -> " << target << "\n";
times++;
todo -= 1;
if (todo == 0) break;

//setting for the next round
doing -= 1;
temp = start;
start = between;
between = target;
target = temp;
}
cout << "共移動了 " << times << " 步\n";
}
}
```