文章

79

粉丝

221

获赞

45

访问

161.2k

头像
给出时与分,求某时刻经过该时分后是几点
P1053
发布于2023年3月24日 10:58
阅读数 1.7k

#include <iostream>
#include <string>
using namespace std;
int main() {
	int n;
	cin >> n;
	string* s = new string[n];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		int h = 0, m = 0, sth = 13, stm = 15;
		for (int j = 0, flag = 0; j < s[i].size(); j++) {
			if (s[i][j] == ':') {
				flag = 1;
				continue;
			}
			if (flag == 0)
				h = h * 10 + s[i][j] - '0';
			else
				m = m * 10 + s[i][j] - '0';
		}
		cout << ((stm + m) / 60 + h + sth) % 24 << ':' << (stm + m) % 60 << endl;
	}
	return 0;
}

输入n个时分,提取出时h与分m,设置起始时分为sth:stm,则经过该时分后的时为((stm + m) / 60 + h + sth) % 24,分为(stm + m) % 60

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发