1. 程式人生 > 其它 >用匯編指令編碼和除錯

用匯編指令編碼和除錯

1. 題目

At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.

Input Specification:

Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:

ID_number Sign_in_time Sign_out_time

where times are given in the format HH:MM:SS, and ID_number

is a string with no more than 15 characters.

Output Specification:

For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.

Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.

Sample Input:

3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40

Sample Output:

SC3021234 CS301133

2. 題意

有M個學生回來機房,每個學生對應一個進機房和出機房時間,找出進機房時間最早和出機房時間最晚的那兩位學生。

3. 思路——簡單模擬

  1. 輸入第一個學生作為基準,將其進機房時間作為開門時間,出機房時間作為關門時間。
  2. 後面學生根據該基準,如果進入時間比其早,則更新開門時間;如果出機房時間比其晚,則更新關門時間。

注:這裡的時間比較,因為時間格式嚴格規定,所以可以直接通過字串比較來得到時間大小。

4. 程式碼

#include <iostream>
#include <string>

using namespace std;

// 這裡時間先後比較,直接使用字串比價即可 
int main()
{
	int n;
	cin >> n;
	// 如果n小於等於0,說明沒有其餘輸入 
	if (n <= 0) return 0;
	string name1, name2;
	string time1, time2;
	cin >> name1 >> time1 >> time2;
	name2 = name1;
	n -= 1;
	string idNum, inTime, outTime; 
	while (n--)
	{
                cin >> idNum >> inTime >> outTime;
		// 比較當前使用者進機房時間和開門時間,如果較小,則更新開門時間 
		if (inTime.compare(time1) < 0)
		{
			time1 = inTime;
			name1 = idNum;
		} 
		// 比較當前使用者出機房時間和關門時間,如果較大,則更新關門時間 
		if (outTime.compare(time2) > 0)
		{
			time2 = outTime;
			name2 = idNum;
		}
	}
	cout << name1 << " " << name2 << endl;
	return 0;
}