#include #include #include using namespace std; const int SIZE = 5; vector pegs[3]; string str; void display() { for (int i=SIZE-1; i > -1; --i) { for (int j=0; j < 3; j++) if (i < pegs[j].size()) cout << pegs[j][i] << '\t'; else cout << "|\t"; cout << '\n'; } getline( cin, str ); } void move( int n, int from, int to, int aux ) { if (n == 1) { pegs[to].push_back( pegs[from].back() ); pegs[from].pop_back(); display(); return; } move( n-1, from, aux, to ); pegs[to].push_back( pegs[from].back() ); pegs[from].pop_back(); display(); move( n-1, aux, to, from ); } int main( void ) { for (int i=SIZE; i > 0; --i) pegs[0].push_back( i ); display(); move( SIZE, 0, 2, 1 ); } #if 0 1 | | 2 | | 3 | | 4 | | 5 | | | | | 2 | | 3 | | 4 | | 5 | 1 | | | | | | 3 | | 4 | | 5 2 1 #endif