3298 | 2023-02-24 17:28:31 | zsombor | Hanoi tornyai variáns (45) | cpp17 | Compilation error |
#include <iostream>
#include <vector>
using namespace std;
int a, mx = 0;
vector <vector <int>> v(4);
vector <pair <int, int>> lep;
vector <pair <int, int>> ans1;
vector <pair <int, int>> ans2;
int hol(int x) {
for (int& i : v[1]) if (i == x) return 1;
for (int& i : v[2]) if (i == x) return 2;
for (int& i : v[3]) if (i == x) return 3;
return 0;
}
void hanoi(int x, int ra) {
if (!x) return;
int rol = hol(x);
if (rol != ra) {
hanoi(x - 1, 6 / rol / ra);
v[rol].pop_back();
v[ra].push_back(x);
lep.push_back({ rol,ra });
}
hanoi(x - 1, ra);
}
int main()
{
while (cin >> a && a) { v[1].push_back(a); mx++; }
while (cin >> a && a) { v[2].push_back(a); mx++; }
while (cin >> a && a) { v[3].push_back(a); mx++; }
hanoi(mx, 1);
ans1 = lep;
for (int i = 1; i <= 3; i++) v[i].resize(0);
while (cin >> a && a) v[1].push_back(a);
while (cin >> a && a) v[2].push_back(a);
while (cin >> a && a) v[3].push_back(a);
hanoi(mx, 1);
ans2 = lep;
cout << ans1.size() + ans2.size() << endl;
for (auto p : ans1) cout << p.first << " " << p.second << endl;
reverse(ans2.begin(), ans2.end());
for (auto p : ans2) cout << p.second << " " << p.first << endl;
}
exit status 1
main.cpp: In function 'int main()':
main.cpp:47:5: error: 'reverse' was not declared in this scope
47 | reverse(ans2.begin(), ans2.end());
| ^~~~~~~
Exited with error status 1