fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int time1, time2;
  5. int order;
  6. int direction; //north = 2, west =3, south =4, east = 1
  7. int x = 0, y = 0;
  8. scanf("%d", & time2);
  9. y = (time2 == 0)? 0 : 10 * time2;
  10. time1 = time2;
  11. do{
  12. scanf("%d", & order);
  13. scanf("%d", & time2);
  14. while(order == 1){
  15. switch(direction){
  16. case 2:
  17. x = x -10 * (time2 - time1) ;
  18. y = y ;
  19. direction = 3;
  20. time1 = time2;
  21. break;
  22.  
  23. case 3:
  24. x = x;
  25. y = y - 10 * (time2 - time1);
  26. direction = 4;
  27. time1 = time2;
  28. break;
  29.  
  30. case 4:
  31. x = x + 10 * (time2 - time1);
  32. y =y;
  33. direction = 1;
  34. time1= time2;
  35. break;
  36.  
  37. case 1:
  38. x = x;
  39. y = y+ 10 * (time2 - time1);
  40. direction = 2;
  41. time1= time2;
  42. break;
  43. }
  44. }
  45.  
  46. while (order == 2){
  47. switch(direction){
  48. case 2:
  49. x = x + 10 * (time2 - time1) ;
  50. y = y ;
  51. direction = 1;
  52. time1 = time2;
  53. break;
  54.  
  55. case 3:
  56. x = x;
  57. y = y + 10 * (time2 - time1);
  58. direction = 2;
  59. time1 = time2;
  60. break;
  61.  
  62. case 4:
  63. x = x - 10 * (time2 - time1);
  64. y =y;
  65. direction = 3;
  66. time1= time2;
  67. break;
  68.  
  69. case 1:
  70. x = x;
  71. y = y- 10 * (time2 - time1);
  72. direction = 4;
  73. time1= time2;
  74. break;
  75. }
  76. }
  77. }while(order == 3);
  78. printf("%d\n", x);
  79. printf("%d\n", y);
  80.  
  81. return 0;
  82. }
Time limit exceeded #stdin #stdout 5s 2248KB
stdin
5
1 
10 
2 
15 
3
stdout
Standard output is empty