fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <iterator>
  5. #include <vector>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <iomanip>
  9.  
  10.  
  11. using namespace std;
  12.  
  13. // string split
  14. vector<string> split(const string & s, const string & delim, const bool keep_empty = true) {
  15. vector<string> result;
  16.  
  17. if(delim.empty()) {
  18. result.push_back(s);
  19. return result;
  20. }
  21.  
  22. string::const_iterator substart = s.begin(), subend;
  23. while(true) {
  24. subend = search(substart, s.end(), delim.begin(), delim.end());
  25. string temp(substart, subend);
  26. if(keep_empty || !temp.empty()) {
  27. result.push_back(temp);
  28. }
  29. if(subend == s.end()) {
  30. break;
  31. }
  32. substart = subend + delim.size();
  33. }
  34.  
  35. return result;
  36. }
  37.  
  38. ////////
  39. vector<double> compute(string strPoczatek, string strKoniec, double shipLength) {
  40. vector<double> wyniki;
  41. vector<string> vPoczatek = split(strPoczatek, ":");
  42. vector<string> vKoniec = split(strKoniec, ":");
  43. int difference;
  44.  
  45. // string to int start
  46. int km = atoi(vPoczatek[0].c_str());
  47. int min = atoi(vPoczatek[1].c_str());
  48. int sec = atoi(vPoczatek[2].c_str());
  49. int startS = km*3600 + min*60 + sec;
  50.  
  51. // string to int koniec
  52. km = atoi(vKoniec[0].c_str());
  53. min = atoi(vKoniec[1].c_str());
  54. sec = atoi(vKoniec[2].c_str());
  55. int koniecS = km*3600 + min*60 + sec;
  56.  
  57. if(koniecS > startS) {
  58. difference = koniecS - startS;
  59. } else {
  60. difference = startS - koniecS;
  61. }
  62.  
  63. wyniki.push_back( ((3600 * shipLength) / difference) / 1000 ); // km/h
  64. wyniki.push_back( ((3600 * shipLength) / difference) / 1852 ); // mile/h
  65.  
  66. return wyniki;
  67. }
  68.  
  69. int main() {
  70. vector< double > results;
  71. string start, koniec;
  72. double length;
  73.  
  74. while(cin >> start >> koniec >> length){
  75. results = compute(start, koniec, length);
  76. cout << setprecision(1) << fixed << results[0] << " " << results[1] << endl;
  77. }
  78.  
  79. return 0;
  80. }
Success #stdin #stdout 0s 3480KB
stdin
23:40:01 23:40:23 269.1  
00:00:00 00:00:08 100
stdout
44.0 23.8
45.0 24.3