Source code for submission s1236

ants.cpp

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <list>
  6. #include <map>
  7.  
  8. using namespace std;
  9.  
  10. int main(){
  11.  
  12. int L, A;
  13. vector<int> li;
  14.  
  15. while (cin >> L >> A){
  16. int steps ;
  17. char r;
  18. int rtime = -1,ltime = -1;
  19. char rWin,lWin;
  20. int lefts, rights;
  21. lefts = rights = 0;
  22. li.clear();
  23. for (int i = 0; i < A; i++){
  24. cin >> steps >> r;
  25. li.push_back(steps);
  26. if (r == 'R'){
  27. rights++;
  28. int t= L - steps;
  29. if (rtime < t){
  30. rtime = t;
  31. rWin = r;
  32. }
  33. } else {
  34. lefts++;
  35. int t = steps;
  36. if (ltime < t){
  37. ltime = t;
  38. lWin = r;
  39. }
  40.  
  41. }
  42.  
  43. }
  44. sort(li.begin(), li.end());
  45. if (ltime == rtime){ //two winners
  46. cout << "The last ant will fall down in "<< ltime << " seconds - started at " << li[lefts-1] << " and "<<li[A-rights]<< "." << endl;
  47.  
  48. } else if (ltime > rtime) {
  49. cout << "The last ant will fall down in "<< ltime << " seconds - started at " << li[lefts-1] << "." << endl;
  50. } else {
  51. cout << "The last ant will fall down in "<< rtime << " seconds - started at " << li[A-rights] << "." << endl;
  52.  
  53. }
  54.  
  55. }
  56.  
  57. return 0;
  58. }
  59.