Advertisement
DavidsonDFGL

Esquerda Volver!

Apr 20th, 2016
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. char processarComandos(string comandos)
  6. {
  7.     char resp[] = {'N','O','S','L'};
  8.  
  9.     int direcao    = 0;
  10.     int proxEstado = 0;
  11.  
  12.     for(int i=0; i<comandos.length(); i++)
  13.     {
  14.         direcao = !((int)comandos[i] & 1) * 180 + 90;
  15.         proxEstado = (proxEstado + direcao) % 360;
  16.     }
  17.     return resp[ proxEstado / 90 ];
  18. }
  19.  
  20. int main()
  21. {
  22.     int numComandos = 0;
  23.     string comandos;
  24.     cin>>numComandos;
  25.  
  26.     while(numComandos > 0)
  27.     {
  28.         cin>>comandos;
  29.         char r = processarComandos(comandos);
  30.         cout<<r<<"\n";
  31.         cin>>numComandos;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement