Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://pastebin.com/hQRdceCL */
- #include <iostream>
- using namespace std;
- const int n = 6;
- int a[n]{};
- int b[n]{};
- int c[n]{};
- void init() {
- for (int k = 0; k < n; k++) {
- a[k] = k + 1;
- }
- }
- void show_tower(int* x) {
- cout << "(";
- for (int k = 0; k < n - 1; k++) {
- cout << x[k] << ", ";
- }
- cout << x[n - 1];
- cout << ")";
- }
- void show_towers() {
- show_tower(a);
- cout << " ";
- show_tower(b);
- cout << " ";
- show_tower(c);
- cout << endl;
- }
- int num_iter = 0;
- void move(int* from, int* to) {
- num_iter++;
- int k = 0;
- while (k < n && from[k] == 0)
- k++;
- int m = 0;
- while (m < n && to[m] == 0)
- m++;
- if (k < n)
- if (m > 0 && ((m == n) || from[k] < to[m])) {
- to[m - 1] = from[k];
- from[k] = 0;
- }
- }
- bool is_good() {
- for (int k = 0; k < n - 1; k++) {
- if (a[k + 1] < a[k] ||
- b[k + 1] < b[k] ||
- c[k + 1] < c[k])
- return false;
- }
- return true;
- }
- void hanoi() {
- init();
- //cout << is_good();
- show_towers();
- move(a, c);
- show_towers();
- move(a, b);
- show_towers();
- move(c, b);
- show_towers();
- move(a, c);
- show_towers();
- move(b, a);
- show_towers();
- move(b, c);
- show_towers();
- move(a, c);
- show_towers();
- }
- void hanoi_solver(int m, int* from, int* tmp, int* to) {
- if (m > 0) {
- hanoi_solver(m - 1, from, to, tmp);
- move(from, to);
- show_towers();
- hanoi_solver(m - 1, tmp, from, to);
- }
- }
- void test_play() {
- init();
- show_towers();
- hanoi_solver(n, a, b, c);
- cout << num_iter << endl;
- }
- int fun(char s[]) {
- if (strcmp(s, "123") == 0)
- return 123;
- else
- return 0;
- }
- void test_str_vs_num() {
- char str1[] = "124.0a";
- const char* str2 = "125.5";
- std::string str3 = "126.6";
- /*
- Поясняется проблематика
- int d = fun(str1);
- cout << d + 21 << endl;
- cout << (int(str1[0]) -48)+13 << " "
- << (int(str1[1]) -48)+13 << " "
- << (int(str1[2]) -48)+13 << endl;
- cout << 1+1 << endl;
- cout << char('1' + 1) << endl;
- */
- cout << atoi(str1) + 13 << endl;
- cout << atoi(str2) + 13 << endl;
- cout << atoi(str3.data()) + 13 << endl;
- cout << atof(str1) + 13 << endl;
- cout << atof(str2) + 13 << endl;
- cout << atof(str3.data()) + 13 << endl;
- char buff[16];
- _itoa_s(768, buff, 2);
- cout << buff << endl;
- }
- int main() {
- test_str_vs_num();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement