PAT A1006 Sign In and Sign Out (25)

AC代码

#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
struct Sign {
    char SignInNumber[20];
    int h, m, s;
}earlist, least, temp;
/*
struct Time {
    int h, m, s
} left, right, temp;
*/
void init() {
    earlist.h = 24;
    earlist.m = 59;
    earlist.s = 59;
    least.h = 0;
    least.m = 0;
    least.s = 0;
}
bool lessEqu(Sign a, Sign b) {
    if(a.h != b.h) return a.h <= b.h;
    else if(a.m != b.m) return a.m <= b.m;
    else return a.s <= b.s;
}

bool moreEqu(Sign a, Sign b) {
    if(a.h != b.h) return a.h >= b.h;
    else if(a.m != b.m) return a.m >= b.m;
    else return a.s >= b.s;
}

int main(){
    init();
    #ifdef ONLINE_JUDGE
    #else
        freopen("1.txt", "r", stdin);
    #endif // ONLINE_JUDGE}
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        char name[20] = {0};
        scanf("%s %d:%d:%d", temp.SignInNumber, &temp.h, &temp.m, &temp.s);
        if(lessEqu(temp, earlist)) {
           earlist = temp;
           //earlist.SignInNumber = name;
        }
        //scanf("%d:%d:%d", &temp.h, &temp.m. &temp.s);
        scanf("%d:%d:%d", &temp.h, &temp.m, &temp.s);
        if(moreEqu(temp, least)) {
           least = temp;
           //least.SignInNumber = name;
        }
    }
    printf("%s %s", earlist.SignInNumber, least.SignInNumber);
    return 0;
}
posted @ 2019-08-03 21:55  哨音  阅读(144)  评论(0编辑  收藏  举报