Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <cstdio>
  5. using namespace std;
  6.  
  7. int check(string mov ,int num){
  8.  
  9.             if (mov[0] == 'L')
  10.                 return num -1;
  11.             else if (mov[0] == 'R')
  12.                 return num+1;
  13.             else return 0;
  14. }
  15.  
  16. int check2(vector<string> v , int pos){
  17.  
  18.  
  19.             char last = v[pos].back();
  20.             int compare = last - '0' ;
  21.  
  22.             if (v[compare-1].front() == 'S' ){
  23.                                
  24.                 return check2(v,compare-1);
  25.                            
  26.             }else{
  27.                         return check(v[compare-1],0);
  28.             }
  29. }
  30.  
  31. int main(){
  32.  
  33.     string count;
  34.     getline(cin,count);
  35.  
  36.     for (int i = 0; i < std::stoi(count); ++i)
  37.     {
  38.        
  39.         vector<string> instructions;
  40.    
  41.         int pos = 0;
  42.         int test =0;
  43.         string in;
  44.  
  45.         string qtd;
  46.         getline(cin,qtd);
  47.        
  48.         int aux = std::stoi(qtd);
  49.  
  50.         //prencher vetor de instrucoes
  51.         for (int j = 0; j < aux; ++j)
  52.         {
  53.                                
  54.                 getline(cin,in);
  55.                 instructions.push_back(in);
  56.             }
  57.  
  58.             //percorre o vetor ate achar alguma istrucao que comeca com S
  59.         for (int q = 0; q < instructions.size(); ++q)
  60.         {
  61.  
  62.                 //achou chama check2 pra recursao
  63.                 if (instructions[q].front() == 'S'){
  64.  
  65.                     test = test + check2(instructions,q);
  66.            
  67.                
  68.                 }else{
  69.                     //aqui eu apenas uso left/right
  70.                     test = test + check(instructions[q],pos);
  71.        
  72.                 }
  73.        
  74.         }
  75.         cout << test << endl;
  76.         test = 0;
  77.     }
  78.   return 0;
  79.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement