Monday, February 27, 2017

UVa 12503 - Robot Instructions

// UVa 12503 - Robot Instructions

#include <iostream>
#include <string>
using namespace std;

int main() {
	int cases;
	for (cin >> cases; cases; cases--) {
		char command[101];
		int ref[101];
		int count;
		cin >> count;
		int robot = 0;
		for (int i = 1; i <= count; i++) {
			string word;
			cin >> word;
			ref[i] = i;
			command[i] = word[0];
			if (command[i] == 'S') {
				cin >> word >> ref[i];
				while (command[ref[i]] == 'S') {
					ref[i] = ref[ref[i]];
				}
			} else {
				ref[i] = i;
			}

			if (command[ref[i]] == 'L')
				robot--;
			else
				robot++;
		}
		cout << robot << endl;
	}
	return 0;
}

No comments:

Post a Comment