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 43 44 45 46 47 48 49
|
#include <iostream>
#include <string>
#include <stdexcept>
using namespace std;
void count(int iter, int x, int y, int finalx, int finaly, string letters, bool& result)
{
if ((x == finalx) && (y == finaly))
{
result = true;
return;
}
else
{
for (int i = iter; i < letters.size(); i++)
{
if (letters.at(i) == 'l')
{ //cout << y;
count((iter + 1), (x), (y - 1), finalx, finaly, letters, result);
}
else if (letters.at(i) == 'r')
{ //cout << y;
count((iter + 1), (x), (y + 1), finalx, finaly, letters, result);
}
else if (letters.at(i) == 'u')
{ //cout << x;
count((iter + 1), (x - 1), (y), finalx, finaly, letters, result);
}
else if (letters.at(i) == 'd')
{ //cout << x;
count((iter + 1), (x + 1), (y), finalx, finaly, letters, result);
}
}
}
}
int main() {
int iter = 0, x = 9, y = 2, finalx = 0, finaly = 3;
bool result;
string letters = "uulluurrruuuulul";
count(iter, x, y, finalx, finaly, letters, result);
cout << result;
return 0;
}
|