基本思路
- 搞一个结构体做记录,然后比较每个记录的时间先后,输出最早进入和最后离开的人
#include <bits/stdc++.h> using namespace std; struct notes{ char id[20]; int hh, mm, ss; // }tmp, earliest, lastest; bool earlier(notes object, notes target){ if(object.hh != target.hh){ return target.hh < object.hh; } if(object.mm != target.mm){ return target.mm < object.mm; } return target.ss < object.ss; } int main(int argc, char* argv[]) { char a; int n; cin >> n; earliest.hh = 0, earliest.mm = 0, earliest.ss = 0; lastest.hh = 24, lastest.mm = 60, lastest.ss = 60; for(int i = 0; i < n; i++){ // 用字符 a 接收 ":" cin >> a >> tmp.hh >> a >> tmp.mm >> a >> tmp.ss; if(earlier(earliest, tmp)){ earliest = tmp; } cin >> a >> tmp.hh >> a >> tmp.mm >> a >> tmp.ss; if(earlier(lastest, tmp)){ lastest = tmp; } } cout << earliest.id << ' ' << lastest.id << endl; return 0; }