这个和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;
}