Source code for submission s665

ants.cpp

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <set>
  4.  
  5. using namespace std;
  6.  
  7. int main ( ) {
  8. int length, cnt, maxL, maxR, pos ,cntR, cntL, AI;
  9. set<int> startPos;
  10. char c;
  11. while(cin >> length >> cnt) {
  12. startPos.clear();
  13. cntR = cntL = 0;
  14. AI = 0;
  15. maxL = length;
  16. maxR = 0;
  17. while(cnt--) {
  18. cin >> pos;
  19. c = cin.get();
  20. c = cin.get();
  21. if(c == 'R' && pos < maxL) {maxL = pos; cntR++;}
  22. if(c == 'L' && pos > maxR) {maxR = pos; cntL++;}
  23. startPos.insert(pos);
  24. }
  25. //int finalPos1;
  26. int n = 0;
  27. set<int>::iterator iter, iter2;
  28. for ( iter = startPos . begin(); iter != startPos . end(); iter++, n++ )
  29. {
  30. if ( n == cntR ) break;
  31. }
  32.  
  33. cout << "The last ant will fall down in ";
  34. if(maxR >= length - maxL) cout << maxR;
  35. else cout << (length - maxL);
  36. cout << " seconds - started at ";
  37. if(maxR == length - maxL && cntR > 0 && cntL > 0) {iter2 = ++iter; iter--; cout << *iter << " and " << *(iter2);}
  38. else if(maxR >= length - maxL || cntR == 0 ) cout << *iter;
  39. else if(maxR <= length - maxL || cntL == 0 ) {iter2 = ++iter; iter--; cout << *iter2;}
  40. /*
  41. if(maxR > length - maxL) cout << startPos[cntR-1];
  42. if(maxR < length - maxL)cout << startPos[cntR];
  43. if(maxR == length - maxL) cout << startPos[cntR-1] << " and " << startPos[cntR];
  44. */
  45. cout << "." << endl;
  46. //for(int i = 0; i < cntcp; i++) cout << "i" << startPos.[i] << endl;
  47. }
  48.  
  49. return 0;
  50. }
  51.  
  52. /*
  53. 90000 1
  54. 0 R
  55. 10 1
  56. 0 L
  57. 14 5
  58. 3 L
  59. 6 L
  60. 13 L
  61. 8 R
  62. 1 R
  63.  
  64. */
  65.