Guest User

Untitled

a guest
May 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int times[10000] = {0};
  4. int hour_st,minute_st,hour_fn,minute_fn;
  5. string time_question;
  6. string s,temp;
  7. //Assume input from file name "inputf.in"
  8.  
  9. /*Bus 1 A 10:00 D 10:05
  10. Bus 2 A 10:05 D 10:15
  11. Bus 3 A 10:05 D 10:30
  12. Bus 4 A 09:00 D 10:05
  13. Bus 5 A 08:05 D 10:45
  14. Bus 6 A 07:05 D 13:30
  15. Bus 7 A 10:00 D 10:05
  16. Bus 8 A 10:05 D 10:15
  17. Bus 9 A 10:05 D 10:30
  18. Bus 10 A 09:00 D 10:05
  19. Bus 11 A 11:05 D 12:45
  20. Bus 12 A 07:05 D 13:40 // test-cases
  21. 10:10 // question minute-x
  22. */
  23.  
  24. /*
  25. -Assume time is Inclusive
  26. -Big O = O(n) precompute the data, O(1) answer question
  27. -count the number of buses at xx::yy time in format hour*100+minutes, this is work because
  28. the number of minutes wont exceec 60 ( < 100).
  29. */
  30.  
  31. int main(){
  32. ios_base::sync_with_stdio(false);
  33. cin.tie(0);
  34. ifstream iFile("inputf.in");
  35. while (true) {
  36. getline(iFile,s);
  37. if (s[0]!='B') break;
  38. stringstream str(s);
  39. string w1,w2;
  40. while (str >> w1 >> w2){
  41. if (w1 == "A"){
  42. temp.clear();
  43. temp+=w2[0];
  44. temp+=w2[1];
  45. hour_st = stoi(temp);
  46. temp.clear();
  47. temp+=w2[3];
  48. temp+=w2[4];
  49. minute_st = stoi(temp);
  50. //cout<<temp<<" "<<w2<<"\n";
  51. }
  52. if (w1 == "D"){
  53. temp.clear();
  54. temp+=w2[0];
  55. temp+=w2[1];
  56. hour_fn = stoi(temp);
  57. temp.clear();
  58. temp+=w2[3];
  59. temp+=w2[4];
  60. minute_fn = stoi(temp);
  61. }
  62. }
  63. while (true){
  64. times[hour_st*100+minute_st]++;
  65. //cout<<hour_st<<" "<<minute_st<<"\n";
  66. ++minute_st;
  67. if (minute_st == 60){
  68. minute_st = 0;
  69. ++hour_st;
  70. }
  71. if (minute_st == minute_fn and hour_st == hour_fn){
  72. times[hour_st*100+minute_st]++;
  73. break;
  74. }
  75. }
  76. //cout<<minute_st<<" "<<minute_fn<<" "<<hour_st<<" "<<hour_fn<<"\n";
  77. if( iFile.eof() ) break;
  78. }
  79. temp.clear();
  80. temp+=s[0];
  81. temp+=s[1];
  82. int min = stoi(temp);
  83. temp.clear();
  84. temp+=s[3];
  85. temp+=s[4];
  86. int hour = stoi(temp);
  87. //cout<<hour<<" "<<min<<"\n";
  88. cout<<times[hour*100 + min]<<"\n";
  89. }
Add Comment
Please, Sign In to add comment