1006 Sign In and Sign Out

#include<iostream>
#include<vector>
#include<sstream>
using namespace std;

struct Person
{
	string ID_number;
	string Sign_in_time;
	string Sign_out_time;
};

int main() {
	int M;
	cin >> M;
	vector<Person> P;
	for (int i = 0; i < M; i++) {
		Person p = Person();
		cin >> p.ID_number >> p.Sign_in_time >> p.Sign_out_time;
		P.push_back(p);
	}
	int min1 = 60 , min2 = 60 , min3 = 60 ,  indexmin = 0;
	int temp1, temp2, temp3;
	for (int i = 0; i < M; i++) {
		string str = P[i].Sign_in_time;
		string str1 = str.substr(0, 2);
		string str2 = str.substr(3, 2);
		string str3 = str.substr(6, 2);
		stringstream ss1, ss2, ss3;
		ss1 << str1;
		ss1 >> temp1;
		ss2 << str2;
		ss2 >> temp2;
		ss3 << str3;
		ss3 >> temp3;
		
		if (temp1 < min1)
			indexmin = i;
		else if (temp1 == min1) {
			if (temp2 < min2)
				indexmin = i;
			else if (temp2 == min2) {
				if (temp3 < min3) {
					indexmin = i;
				}
			}
		}
		if (indexmin == i) {
			min1 = temp1;
			min2 = temp2;
			min3 = temp3;
		}
	}

	int max1 = 00, max2 = 00, max3 = 00, indexmax = 0;
	for (int i = 0; i < M; i++) {
		string str = P[i].Sign_out_time;
		string str1 = str.substr(0, 2);
		string str2 = str.substr(3, 2);
		string str3 = str.substr(6, 2);
		stringstream ss4, ss5, ss6;
		ss4 << str1;
		ss4 >> temp1;
		ss5 << str2;
		ss5 >> temp2;
		ss6 << str3;
		ss6 >> temp3;

		if (temp1 > max1)
			indexmax = i;
		else if (temp1 == min1) {
			if (temp2 > max2)
				indexmax = i;
			else if (temp2 == max2) {
				if (temp3 > max3) {
					indexmax = i;
				}
			}
		}
		if (indexmax == i) {
			max1 = temp1;
			max2 = temp2;
			max3 = temp3;
		}
	}

	cout << P[indexmin].ID_number << " " << P[indexmax].ID_number;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值