#include "stdafx.h" #include <iostream> #include <string> #include <cassert> using namespace std; const int N = 20; struct vez { int k; int p[N]; }; vez x,y,z; void vynuluj (vez &a) { a.k=0; for (int i=0;i<N; i++) a.p[i]=0; } void vypln (vez &a) { a.k=N; for (int i=0;i<N; i++) a.p[i]=N-i; } void vypis (vez &a) { for (int i=0; i<N; i++) if (i < a.k) { char c; int t = a.p[i]; if (t <= 9) c = '0' + t; else c = 'A' + t - 10; cout << c; } else cout << " "; } void krok (vez &a, vez &b) { assert (a.k > 0); int v = a.p[a.k-1]; a.p [a.k-1] = 0; a.k--; assert (b.k < N); if (b.k > 0) assert (b.p [b.k-1] > v); // <--- b.p[b.k] = v; b.k++; // b.p[b.k++] = a.p[--a.k]; vypis (x); cout << "|" ; vypis (y); cout << "|"; vypis (z); cout << endl; } void prenos(vez &a, vez& b, vez& c, int h){ if (h > 1) prenos (a, c, b, h-1); krok (a, c); if (h > 1) prenos (b, a, c, h-1); } int _tmain(int argc, _TCHAR* argv[]) { cout << "Veze" << endl; vypln (x); vynuluj (y); vynuluj (z); prenos (x, y, z, N); system ("pause"); return 0; }