1006 Sign In and Sign Out

1006 Sign In and Sign Out_第1张图片
1006 Sign In and Sign Out_第2张图片
1006 Sign In and Sign Out_第3张图片
1006 Sign In and Sign Out_第4张图片

#define _CRT_SECURE_NO_WARNINGS
#include
using namespace std;
int main() 
{
    int n, minn = INT_MAX, maxn = INT_MIN;//INT_MAX = 2^31-1,INT_MIN= -2^31
    scanf("%d", &n);
    string first, last;
    for (int i = 0; i < n; i++) 
    {
        string bianhao;
        cin >> bianhao;
        int h1, m1, s1, h2, m2, s2;//小时,分钟,秒钟
        scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
        int tempIn = h1 * 3600 + m1 * 60 + s1;
        int tempOut = h2 * 3600 + m2 * 60 + s2;
        if (tempIn < minn) 
        {
            minn = tempIn;
            first = bianhao;
        }
        if (tempOut > maxn) 
        {
            maxn = tempOut;
            last = bianhao;
        }
    }
    cout << first << " " << last;
    return 0;
}

你可能感兴趣的:(PAT)