Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <math.h>
- #include <stdlib.h>
- using namespace std;
- class Mars
- {
- public:
- int position, speed;
- Mars(const char * seq)
- {
- position = 0;
- speed = 1;
- for (int i = 0; i < strlen(seq); i++)
- {
- if (seq[i] == 'a')
- a();
- if (seq[i] == 'r')
- r();
- }
- }
- void a()
- {
- position += speed;
- speed *= 2;
- }
- void r()
- {
- speed = speed > 0 ? -1 : 1;
- }
- };
- int x;
- void generateSeq(char * str, int pos)
- {
- if (pos >= strlen(str))
- {
- Mars *m = new Mars(str);
- if (m->position == x)
- {
- cout << "FIND: " << str << endl;
- cout << "N: " << strlen(str) << endl;
- delete m;
- system("pause");
- exit(0);
- }
- delete m;
- //cout << str << endl;
- return;
- }
- generateSeq(str, pos + 1);
- str[pos] = 'r';
- generateSeq(str, pos + 1);
- str[pos] = 'a';
- }
- int main()
- {
- cin >> x;
- for (int i = 1; i < 100; i++)
- {
- char *s = new char[i + 1];
- for (int j = 0; j < i; j++)
- s[j] = 'a';
- s[i] = '\0';
- generateSeq(s, 0);
- delete[] s;
- }
- //Mars* m1 = new Mars("");
- //char s[5] = "aaaa";
- //cin >> s;
- // generateSeq(s, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement