PAT Advanced Level 1006 Sign In and Sign Out

原题传送门

1. 问题描述

2. Solution

1、思路分析
遍历,求最大值、最小值,字符串比较即可。

2、代码实现

// PAT Advance Level 1006 // Ye Qiu  #include <iostream> #include <cstdio> #include <string> #include <algorithm>  using namespace std;  int main() { #ifdef ONLINE_JUDGE #else     freopen(input/1006.txt, r, stdin); #endif     int m;     string idNumbers, singIn, singOut, earlyId, lateId, earlyTime = 23:59:59, lateTime = 00:00:00;     scanf(%d, &m);     for (int i = 0; i < m; i++) {         cin >> idNumbers >> singIn >> singOut;         if (singIn < earlyTime) {             earlyTime = singIn;             earlyId = idNumbers;         }         if (singOut > lateTime) {             lateTime = singOut;             lateId = idNumbers;         }     }     cout << earlyId <<   << lateId;     return 0; } 

3、复杂度分析
时间复杂度: O(n)
空间复杂度: O(1)