Source code for submission s1065

ants.cpp

  1. #include<stdio.h>
  2.  
  3. int main(){
  4.  
  5. int l, ant;
  6.  
  7. scanf("%d %d", &l, &ant);
  8.  
  9. char pole[l];
  10.  
  11. for(int i = 0;i < l;i++){
  12.  
  13. pole[i] = '0';
  14.  
  15. }
  16.  
  17. int poz;
  18. char index;
  19.  
  20. for(int x = 0; x < ant ;x++){
  21.  
  22. scanf("%d %c", &poz, &index);
  23.  
  24. pole[poz]=index;
  25.  
  26. }
  27.  
  28. int left = 0;
  29. int right = 0;
  30. int v = 0;
  31. int pozright = 0;
  32.  
  33. int y = l;
  34.  
  35. while ((left == 0)){
  36.  
  37. if (pole[y] == 'L'){
  38.  
  39. left = y + 1;
  40. break;
  41. }
  42.  
  43. if (y == 0) {break;}
  44.  
  45. y--;
  46. }
  47.  
  48. while(right == 0) {
  49.  
  50. if (pole[v] == 'R'){
  51.  
  52. right = v;
  53. pozright = right;
  54. right = l - right + 1;
  55. }
  56.  
  57. if(v == l) {break;}
  58.  
  59. v++;
  60.  
  61.  
  62. }
  63.  
  64. if (right > left){
  65.  
  66. printf("The last ant will fall down in %d seconds - started at %d\n", right - 1, pozright);
  67.  
  68. }else if (left > right){
  69.  
  70. printf("The last ant will fall down in %d seconds - started at %d\n", left - 1, left - 1);
  71.  
  72. }else{
  73.  
  74. int a, b;
  75.  
  76. for (int i = l / 2; i < l; i++){
  77.  
  78. if (pole[i] != '0'){
  79.  
  80. b = i;
  81. break;
  82. }
  83.  
  84. }
  85.  
  86. for(int i = (l / 2) - 1; i > 0; i-- ){
  87.  
  88. if (pole[i] != '0'){
  89.  
  90. a = i;
  91. break;
  92.  
  93.  
  94. }
  95.  
  96.  
  97. }
  98.  
  99. printf("The last ant will fall down in %d seconds - started at %d and %d\n", right - 1, a, b);
  100.  
  101. }
  102.  
  103. return 0;
  104.  
  105. }
  106.  
  107.