Hej, napisałem oto taki kodzik, wprowadzam dane tak jak w przykładzie i dostaję poprawne wyniki, ale jak zadanie zgłaszam to już jest monit: "błędna odpowiedź", mógłby mi ktoś podpowiedzieć gdzie robię błąd, że zadanie nie przechodzi?
zadanie: http://pl.spoj.com/problems/AL_10_11/
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
using namespace std;
// string split
vector<string> split(const string & s, const string & delim, const bool keep_empty = true) {
vector<string> result;
if(delim.empty()) {
result.push_back(s);
return result;
}
string::const_iterator substart = s.begin(), subend;
while(true) {
subend = search(substart, s.end(), delim.begin(), delim.end());
string temp(substart, subend);
if(keep_empty || !temp.empty()) {
result.push_back(temp);
}
if(subend == s.end()) {
break;
}
substart = subend + delim.size();
}
return result;
}
////////
vector<double> compute(string strPoczatek, string strKoniec, double shipLength) {
vector<double> wyniki;
vector<string> vPoczatek = split(strPoczatek, ":");
vector<string> vKoniec = split(strKoniec, ":");
int difference;
// string to int start
int km = atoi(vPoczatek[0].c_str());
int min = atoi(vPoczatek[1].c_str());
int sec = atoi(vPoczatek[2].c_str());
int startS = km*3600 + min*60 + sec;
// string to int koniec
km = atoi(vKoniec[0].c_str());
min = atoi(vKoniec[1].c_str());
sec = atoi(vKoniec[2].c_str());
int koniecS = km*3600 + min*60 + sec;
if(koniecS > startS) {
difference = koniecS - startS;
} else {
difference = startS - koniecS;
}
wyniki.push_back( ((3600 * shipLength) / difference) / 1000 ); // km/h
wyniki.push_back( ((3600 * shipLength) / difference) / 1852 ); // mile/h
return wyniki;
}
int main() {
vector< double > results;
string start, koniec;
double length;
cin >> start >> koniec >> length;
if(length > 0 && length <= 400) {
results = compute(start, koniec, length);
cout << setprecision(1) << fixed << results[0] << " " << results[1] << endl;
}
return 0;
}