#include <iostream>
#include <string>
using namespace std;
class time
{
public:
time(){}
int hour;
int minute;
};
ostream & operator<<(ostream &out, time &a)
{
if (a.hour <= 9)
out << 0 << a.hour << ":";
else
out << a.hour << ":";
if (a.minute <= 9)
out << 0 << a.minute;
else
out << a.minute;
return out;
}
istream & operator>>(istream &in, time &a)
{
string x;
in >> x;
if (x[0] == 0)
a.hour = x[1] - 48;
else
a.hour = (x[0] - 48) * 10 + x[1] - 48;
if (x[3] == 0)
a.minute = x[4] - 48;
else
a.minute = (x[3] - 48) * 10 + x[4] - 48;
return in;
}
time operator+(time t1, time t2)
{
time t3;
t3.hour = t1.hour + t2.hour;
if (t3.hour >= 24)
t3.hour -= 24;
t3.minute = t1.minute + t2.minute;
while (t3.minute >= 60)
{
t3.hour++;
t3.minute -= 60;
}
return t3;
}
time operator+(time t1, int b)
{
t1.minute += b;
while (t1.minute >= 60)
{
t1.hour++;
t1.minute -= 60;
}
while (t1.hour >= 24)
{
t1.hour -= 24;
}
return t1;
}
int main()
{
time t; cin >> t;
cout << t << ",";
int a;
while (cin >> a)
{
t = t + a;
cout << t << ",";
}
return 0;
}
Mam tu napisany program do zadania na SPOJU
http://pl.spoj.com/problems/WI_DZWON/
W VC++ wszystko mi działa a na Ideone pokazuje, że błąd kompilacji
http://ideone.com/CVM37y
Dlaczego tak się dzieje?