https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ffc8/00000000002d83dc

This is RobotPathDecoding problem from kickstart 2020 RoundB. I have 
written this code in c++ with a recursive function. it works fine with 
testSet1 but gives WA on testSet2
Could any one resolve this issue? If any please do reply.
Thanks
#include <bits/stdc++.h>
#include <vector>
#include <string>
using namespace std;
pair<pair<int, int>, int> xydis(string s)
{
    int x = 0;
    int y = 0;
    int i = 0;
    for (i = 0; s[i] != ')' && s[i] != '\0'; i++)
    {
        if (s[i] == 'N')
            y--;
        if (s[i] == 'S')
            y++;
        if (s[i] == 'E')
            x++;
        if (s[i] == 'W')
            x--;
        if (isdigit(s[i]))
        {
            int n = s[i] - '0';
            pair<pair<int, int>, int> future = xydis(s.substr(i + 2, s.
length() - i - 1));
            cout << "future " << s.substr(i + 2, s.length() - i - 1) << " "
 << future.first.first << " " << future.first.second << " " << future.second
 << endl;
            x += n * future.first.first;
            y += n * future.first.second;
            i += future.second + 2;
        }
    }
    return make_pair(make_pair(x, y), i);
}
int main()
{
    int te;
    cin >> te;
    for (int i = 0; i < te; i++)
    {
        cout << "Case #" << i + 1 << ": ";
        string s;
        cin >> s;

        pair<int, int> result = xydis(s).first;
        int x = result.first + 1;
        int y = result.second + 1;
        if (x <= 0)
            x += 1000000000;
        if (y <= 0)
            y += 1000000000;
        cout << x << " " << y << endl;
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/eb4b9410-73f2-48ad-a033-a171e7224b82%40googlegroups.com.

Reply via email to