-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtowerofhanoi.cpp
More file actions
42 lines (35 loc) · 1 KB
/
towerofhanoi.cpp
File metadata and controls
42 lines (35 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define MOD 1000000007
void towerOfHanoi(int n, char s, char d, char a){
if (n == 1){
cout << "Move disk 1 from rod " << s << " to rod " << d <<endl;
return;
}
towerOfHanoi(n - 1, s, a, d);
cout << "Move disk " << n << " from rod " << s << " to rod " << d << endl;
towerOfHanoi(n - 1, a, d, s);
}
void CowboyBebop(){
int n ;
cin >> n ;
auto start =chrono::high_resolution_clock::now();
towerOfHanoi(n,'A','B','C');
auto stop = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
cout << duration.count() << " μs" << endl;
}
using namespace std;
int main(void){
std::ios_base::sync_with_stdio(false);
// #ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int t = 1;
// cin >> t;
while(t--){
CowboyBebop();
}
return 0;
}