题解 | #重载小于号#

重载小于号

http://www.nowcoder.com/practice/e717e94202304f34b7ed95b2d31fce6b

#include <iostream>
using namespace std;

class Time {

    public:
        int hours;      // 小时
        int minutes;    // 分钟

        Time() {
            hours = 0;
            minutes = 0;
        }

        Time(int h, int m) {
            this->hours = h;
            this->minutes = m;
        }

        void show() {
            cout << hours << " " << minutes << endl;
        }

        // write your code here......
        int operator < (Time& t) {
            if (this->hours * 60 + this->minutes < t.hours * 60 + t.minutes) return 1;
            return 0;
        }

};

int main() {
    int h, m;
    cin >> h;
    cin >> m;

    Time t1(h, m);
    Time t2(6, 6);
	
    if (t1<t2) cout<<"yes"; else cout<<"no";
    return 0;
}
全部评论

相关推荐

02-28 17:01
门头沟学院 C++
俊朗的铁猫希望被捞:兄弟如果只想搞钱的话,你这个简历最适合的其实是辅导机构做dai写啥的真的特别赚
点赞 评论 收藏
分享
02-08 15:53
门头沟学院 Java
CoderEcho:让公司知道便宜没好货
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务