fork(4) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void counter(int &result_X, int &result_Y)
  6. {
  7. int t;
  8. cin >> t;
  9.  
  10. int x = 0, y = 0; //koordynaty
  11.  
  12. for(int i = 0; i < t; i++)
  13. {
  14. int direction, steps;
  15.  
  16. cin >> direction >> steps;
  17.  
  18. switch( direction )
  19. {
  20. case 0: // N
  21. {
  22. y += steps;
  23. break;
  24. }
  25. case 1: // S
  26. {
  27. y -= steps;
  28. break;
  29. }
  30. case 2: // W
  31. {
  32. x -= steps;
  33. break;
  34. }
  35. case 3: // E
  36. {
  37. x += steps;
  38. break;
  39. }
  40. }
  41.  
  42. }
  43. result_X = x;
  44. result_Y = y;
  45. }
  46.  
  47. void show_results(int x, int y)
  48. {
  49.  
  50. if(y == 0 && x == 0)
  51. {
  52. cout << "studnia" << endl;
  53. return;
  54.  
  55. }
  56.  
  57. if(y > 0)
  58. {
  59. cout << 0 << " " << y << endl;
  60. }
  61. else if (y < 0)
  62. {
  63. cout << 1 << " " << y * -1 << endl;
  64. }
  65.  
  66. if(x > 0)
  67. {
  68. cout << 3 << " " << x << endl;
  69. }
  70. else if (y < 0)
  71. {
  72. cout << 2 << " " << x * -1 << endl;
  73. }
  74.  
  75. }
  76.  
  77. int main()
  78. {
  79. int t;
  80. cin >> t;
  81.  
  82. int * x = new int [t];
  83. int * y = new int [t];
  84.  
  85. for (int i = 0; i < t; i++)
  86. {
  87. counter(x[i],y[i]);
  88. }
  89.  
  90.  
  91. for (int i = 0; i < t; i++)
  92. {
  93. show_results(x[i],y[i]);
  94. }
  95.  
  96.  
  97. delete[] x;
  98. delete[] y;
  99.  
  100. return 0;
  101. }
  102.  
Success #stdin #stdout 0s 4392KB
stdin
3
3
1 1
0 2
3 1
4
0 1
2 1
1 1
3 1
2
0 1
0 2
stdout
0 1
3 1
studnia
0 3