Solve of UVA 12503: Robot Instructions
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[110],b,c,d,i,f,j;
char z[100]={'\0'};
cin >> b;
for(i=1;i<=b;i++)
{
cin>>c;
d=0;
for(j=0;j<c;j++)
{
cin>>z;
if(strcmp(z,"LEFT")==0){
a[j]=-1;
d--;
//cout << "YES";
}
else if(strcmp(z,"RIGHT")==0){
a[j]=1;
d++;
}
else if (cin >> z >> f)
{
d+=a[f-1];
a[j]=a[f-1];
}
}
cout<<d<<endl;
}
return 0;
}
No comments:
Post a Comment