Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <cstdio>
- using namespace std;
- int check(string mov ,int num){
- if (mov[0] == 'L')
- return num -1;
- else if (mov[0] == 'R')
- return num+1;
- else return 0;
- }
- int check2(vector<string> v , int pos){
- char last = v[pos].back();
- int compare = last - '0' ;
- if (v[compare-1].front() == 'S' ){
- return check2(v,compare-1);
- }else{
- return check(v[compare-1],0);
- }
- }
- int main(){
- string count;
- getline(cin,count);
- for (int i = 0; i < std::stoi(count); ++i)
- {
- vector<string> instructions;
- int pos = 0;
- int test =0;
- string in;
- string qtd;
- getline(cin,qtd);
- int aux = std::stoi(qtd);
- //prencher vetor de instrucoes
- for (int j = 0; j < aux; ++j)
- {
- getline(cin,in);
- instructions.push_back(in);
- }
- //percorre o vetor ate achar alguma istrucao que comeca com S
- for (int q = 0; q < instructions.size(); ++q)
- {
- //achou chama check2 pra recursao
- if (instructions[q].front() == 'S'){
- test = test + check2(instructions,q);
- }else{
- //aqui eu apenas uso left/right
- test = test + check(instructions[q],pos);
- }
- }
- cout << test << endl;
- test = 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement