1006. Sign In and Sign Out 解析

这个和1005差不多。处理好时间的格式应该没有问题。我把时间全部转换成了秒为单位进行比较。

#include <iostream>
#include <string>

using namespace std;

struct Node
{
	string ID;
	string Login;
	string Loout;
};

int Str2Int(char s) {

	int temp = 0;

	switch (s)
	{
	case '1':temp = 1; break;
	case '2':temp = 2; break;
	case '3':temp = 3; break;
	case '4':temp = 4; break;
	case '5':temp = 5; break;
	case '6':temp = 6; break;
	case '7':temp = 7; break;
	case '8':temp = 8; break;
	case '9':temp = 9; break;
	case '0':temp = 0; break;
	default:
		break;
	}
	return temp;
}

int ChangeTime(string s) {
	int H1, H2, M1, M2, S1, S2;
	H1 = Str2Int(s[0]);
	H2 = Str2Int(s[1]);
	M1 = Str2Int(s[3]);
	M2 = Str2Int(s[4]);
	S1 = Str2Int(s[6]);
	S2 = Str2Int(s[7]);
	int sum = (H1 * 10 + H2) * 3600 + (M1 * 10 + M2) * 60 + (S1 * 10 + S2);
	return sum;
}


//bool CompareIn(Node N1, Node N2) { //N1大返回true 否则false
//	int n1, n2;
//	n1 = ChangeTime(N1.Login);
//	n2 = ChangeTime(N2.Login);
//	if (n1 > n2)
//		return true;
//	else
//	{
//		return false;
//	}
//}
//
//bool CompareOut(Node N1, Node N2) { //N1大返回true 否则false
//	int n1, n2;
//	n1 = ChangeTime(N1.Loout);
//	n2 = ChangeTime(N2.Loout);
//	if (n1 > n2)
//		return true;
//	else
//	{
//		return false;
//	}
//}


int main() {
	
	int N;
	cin >> N;

	struct Node * Data = new Node[N];

	for (int i = 0; i < N; i++) {
		cin >> Data[i].ID >> Data[i].Login >> Data[i].Loout;
	}

	int Out, In, MaxNum, MinNum;
	In = ChangeTime(Data[0].Login);
	Out = ChangeTime(Data[0].Loout);
	MaxNum = MinNum = 0;

	输出时间
	//for (int i = 0; i < N; i++)
	//{
	//	cout << "Login: " << ChangeTime(Data[i].Login) << " " << "LogOut: " << ChangeTime(Data[i].Loout) << endl;
	//}



	for (int i = 1; i < N; i++) {
		if (ChangeTime(Data[i].Login) < In) {		
			In = ChangeTime(Data[i].Login);
			MinNum = i;
		}

		if (ChangeTime(Data[i].Loout) > Out) {
			Out = ChangeTime(Data[i].Loout);
			MaxNum = i;
		}
	}

	cout << Data[MinNum].ID << " " << Data[MaxNum].ID << endl;
	
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值