Advertisement
cacodemon665

Ебаный марсоход

Oct 8th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. class Mars
  9. {
  10. public:
  11.     int position, speed;
  12.  
  13.     Mars(const char * seq)
  14.     {
  15.         position = 0;
  16.         speed = 1;
  17.  
  18.         for (int i = 0; i < strlen(seq); i++)
  19.         {
  20.             if (seq[i] == 'a')
  21.                 a();
  22.  
  23.             if (seq[i] == 'r')
  24.                 r();
  25.         }
  26.     }
  27.     void a()
  28.     {
  29.         position += speed;
  30.         speed *= 2;
  31.     }
  32.     void r()
  33.     {
  34.         speed = speed > 0 ? -1 : 1;
  35.     }
  36. };
  37.  
  38.  
  39. int x;
  40.  
  41. void generateSeq(char * str, int pos)
  42. {
  43.     if (pos >= strlen(str))
  44.     {
  45.         Mars *m = new Mars(str);
  46.         if (m->position == x)
  47.         {
  48.             cout << "FIND:  " << str << endl;
  49.             cout << "N:  " << strlen(str) << endl;
  50.             delete m;
  51.             system("pause");
  52.             exit(0);
  53.         }
  54.         delete m;
  55.         //cout << str << endl;
  56.         return;
  57.     }
  58.  
  59.     generateSeq(str, pos + 1);
  60.  
  61.     str[pos] = 'r';
  62.  
  63.     generateSeq(str, pos + 1);
  64.  
  65.     str[pos] = 'a';
  66. }
  67.  
  68. int main()
  69. {
  70.  
  71.     cin >> x;
  72.  
  73.     for (int i = 1; i < 100; i++)
  74.     {
  75.         char *s = new char[i + 1];
  76.  
  77.         for (int j = 0; j < i; j++)
  78.             s[j] = 'a';
  79.  
  80.         s[i] = '\0';
  81.  
  82.         generateSeq(s, 0);
  83.  
  84.         delete[] s;
  85.     }
  86.     //Mars* m1 = new Mars("");
  87.     //char s[5] = "aaaa";
  88.  
  89.     //cin >> s;
  90. //  generateSeq(s, 0);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement