文章

1

粉丝

0

获赞

0

访问

47

头像
偷菜时间表 题解:
P1053
发布于2026年3月8日 17:22
阅读数 47

#include<iostream>
#include<string>
using namespace std;

// 时间类 
class Time{
	private:
		int h;
		int m;
	public:
		Time(int hour,int mun):h(hour),m(mun){}
		// 重载+运算 
		Time operator+(const Time &t){
			Time d(h,m);
			d.h+=t.h;
			d.h%=24;
			d.m+=t.m;
			// 相加大于一小时 
			if(d.m/60!=0)d.h++;
			d.m%=60;
			return d;
		}
		friend void myPut(const Time &t);
};

void myPut(const Time &t){
	cout<<t.h<<":"<<t.m<<"\n";
}

int main(){
	Time t(13,15);
	int n;
	cin>>n;
	int h,m;
	while(n--){
		// 带字符输入 
		scanf("%d:%d",&h,&m);
		Time d(h,m);
		Time d1=t+d;
		myPut(d1);
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发