- 前引
- 原题题目
- 代码实现
- 提交结果
前引
感觉有点像
C++智商训练营了
原题题目
代码实现
#includeusing namespace std; #define N 100 class CTime { public: CTime() : minutes_(0), seconds_(0) {} CTime(const int& minutes__, const int& seconds__) : minutes_(minutes__), seconds_(seconds__) {} void input() { cin >> minutes_ >> seconds_; } int totalseconds() const { return minutes_ * 60 + seconds_; } CTime operator-(const CTime& other) { CTime tmp(*this); int seconds = totalseconds(); int other_totalseconds = other.totalseconds(); int totalseconds = seconds - other_totalseconds; int new_minutes = totalseconds / 60; int new_seconds = totalseconds % 60; return CTime(new_minutes, new_seconds); } friend ostream& operator<< (ostream& os, const CTime& time); bool beZero() const { return minutes_ == 0 && seconds_ == 0; } public: int minutes_; int seconds_; }; ostream& operator<< (ostream& os, const CTime& time) { return os << time.totalseconds() << endl; } int main() { CTime time[N]; int count = -1; do { count++; time[2 * count].input(); time[2 * count + 1].input(); } while (!(time[2 * count].beZero() && time[2 * count + 1].beZero())); for (int i = 0; i < count; ++i) { cout << time[2 * i + 1] - time[2 * i] << endl; } return 0; }
提交结果



