fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define YES cout << "YES\n";
  4. #define NO cout << "NO\n";
  5. #define opps cout<<-1<<endl;
  6. const ll con = 1e10 + 5;
  7. using namespace std;
  8. void solve() {
  9. int n , x = 0 ;
  10. cin >> n ;
  11. cin.ignore();
  12. vector<string> a;
  13. while (n--){
  14. string s;
  15. getline(cin, s);
  16. if (s == "LEFT") {
  17. x--;
  18. a.push_back("LEFT");
  19. }
  20. else if (s == "RIGHT") {
  21. x++;
  22. a.push_back("RIGHT");
  23. }
  24. else {
  25. string tr = s.substr(8);
  26. int j = stoi(tr);
  27. string we = a[j - 1];
  28. (we == "LEFT") ? x-- : x++;
  29. a.push_back(we);
  30. }
  31. }
  32. cout << x << endl;
  33. }
  34. int main() {
  35. ios::sync_with_stdio(0);
  36. cin.tie(0);
  37. int t = 1;
  38. cin>>t;
  39. while(t--)
  40. solve();
  41. }
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
0