UVA 12503 - Robot Instructions

UVA Sep 1, 2020

Problem PDF

Solution:

#include
#include
int main()
{
    char a[30];
    int t,n,s,e,i,b[110];
    while(scanf("%d",&t)==1)
    {
        while(t--)
        {
            scanf("%d",&n);
            s=0;
            for(i=1;i<=n;i++)
            {
                scanf("%s",a);
                if(strcmp(a,"LEFT")==0)
                {
                    s-=1;
                    b[i]=-1;
                }
                else if(strcmp(a,"RIGHT")==0)
                {
                    s+=1;
                    b[i]=1;
                }
                else
                {
                    scanf("%s%d",a,&e);
                    s+=b[e];
                    b[i]=b[e];
                }
            }
            printf("%d\n",s);
        }
    }
return 0;
}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/12503/12503.cpp

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.