Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main(void)
- {
- int t, n;
- while(cin >> t)
- {
- while(t--)
- {
- cin >> n;
- getchar();
- char str[n][15];
- int pos = 0;
- for(int i = 0; i < n; i++)
- {
- gets(str[i]);
- if(strcmp(str[i], "LEFT") == 0)
- pos--;
- else if(strcmp(str[i], "RIGHT") == 0)
- pos++;
- else
- {
- int b = 1, ind = 0;
- for(int j = strlen(str[i]) - 1; j >= 0 ; j--)
- {
- if(str[i][j] >= '0' && str[i][j] <= '9')
- {
- ind += (str[i][j] - '0') * b;
- b *= 10;
- }
- }
- ind--;
- if(strcmp(str[ind], "LEFT") == 0)
- pos--;
- else if(strcmp(str[ind], "RIGHT") == 0)
- pos++;
- strcpy(str[i], str[ind]);
- }
- }
- cout << pos << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement