Wednesday, June 22, 2016

UVA 12503 - Robot Instructions

#include<bits/stdc++.h>
using namespace std;
int main()
{
   int T;
   cin>>T;
   while(T--){
    int t;
    cin>>t;
    cin.ignore();
    vector<int>v;
    string s;
    int pos=0,line=0;
    while(t--){
        cin>>s;
        if(s=="LEFT"){
            pos--;
            v.push_back(-1);
        }
        else if(s=="RIGHT"){
            pos++;
            v.push_back(1);
        }
        else{
            string t ;
            int ins;
            cin>>t>>ins;
            pos+=v[ins-1];
            v.push_back(v[ins-1]);
        }
    }
     cout<<pos<<'\n';
   }
    return 0;
}

No comments:

Post a Comment