Advertisement
JosepRivaille

P79784: Moviments en el pla

Mar 5th, 2015
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. //Pre: Llegeix una seqüència de coordenades
  6. //Post: Obté la posició final
  7. int main() {
  8.   char c;
  9.   int x, y; //Representa les posicions en un eix de coordenades
  10.   x = 0;
  11.   y = 0;
  12.   while (cin >> c) {
  13.     if (c == 'n') --y; //nord
  14.     else if (c == 's') ++y; //sud
  15.     else if (c == 'e') ++x; //est
  16.     else if (c == 'o') --x; //oest
  17.   }
  18.   cout << '(' << x << ", " << y << ')' << endl;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement