#include <iostream>
using namespace std;
string cardinalDirection(string str1)
{
int c = 0;
string direction = "";
for (int i = 0; i < str1.length(); i++) {
if (str1[0] == '\n')
return NULL;
if (str1[i] == 'L')
c--;
else {
if (str1[i] == 'R')
c++;
}
}
if (c > 0) {
if (c % 4 == 0)
direction = "N";
else if (c % 4 == 1)
direction = "E";
else if (c % 4 == 2)
direction = "S";
else if (c % 4 == 3)
direction = "W";
}
if (c < 0) {
if (c % 4 == 0)
direction = "N";
else if (c % 4 == -1)
direction = "W";
else if (c % 4 == -2)
direction = "S";
else if (c % 4 == -3)
direction = "E";
}
return direction;
}
int main()
{
string str = "LLR";
cout << (cardinalDirection(str)) << endl;
}
Comments
Leave a comment