URI Solution 1574 Robot Instructions - Solution in C, C++ | Ad Hoc
URI Online Judge Solution | Ad Hoc
URI Main Problem Link -
Problem Name: URI Problem 1574 Robot Instructions
Problem Number : URI Problem 1574 Robot Instructions Solution
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus
URI Solution 1574 Robot Instructions Code in CPP:
#include <iostream> #include <string> using namespace std; int main() { int t, n, p, val; string line, sub; cin >> t; for (int i = 0; i < t; ++i) { cin >> n; int array[n + 1]; p = 0; cin.ignore(); for (int j = 0; j < n; ++j) { getline(cin, line); if(line == "LEFT"){ array[j + 1] = -1; }else if(line == "RIGHT"){ array[j + 1] = 1; }else{ sub = line.substr(8); val = stoi( sub ); array[j + 1] = array[val]; } } for (int j = 1; j < (n + 1); ++j) p += array[j]; cout << p << '\n'; } return 0; }
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks