编程介的小学生 2020-02-03 21:48 采纳率: 20.5%
浏览 78

Code Management System 代码管理编写

Problem Description
Jack’s company has a very long program to modify. Each programmer edits some lines of that program and cannot add or delete any lines. A programmer can do three kinds of operations as below:

  • SYNC: At the beginning, every programmer must do this to download the whole program from the code center to their local machine. This operation only executes once for each programmer.

  • MODIFY: Modify a line of the code. The modification work will be temporarily done on the local computer.

  • SUBMIT: Submit one’s whole local code to the code center. The code center will handle all possible changes and then send the whole newest program back to the submitter. We assume that the time duration of handling changes and sending back can be omitted.

The code center records the time and the performer of every operation.
As you see, a programmer can get the program from the code center only when he performs a SYNC or a SUBMIT operation. We call the version in the code center “standard version.” The code center keeps only ONE standard version.

Imagining there are two programmers who download the same version of the program and they both modify the ith line. Then they both submit their programs. Now what will the ith line be in the standard version? Jack figures out a rule. He gives each programmer a unique priority. When a programmer (Let’s name him Tom) modifies the ith line and then submit his program, the code center will handle the content of the ith line following the rules below:

  1. If there was no accepted modification on the ith line before, Tom’s modification will be accepted. That means, the ith line in the standard version becomes the same as the ith line in the program submitted by Tom, and so Tom becomes the author of this line.
  2. Otherwise, if the time of the last accepted modification on the ith line, is earlier than the time when Tom got the program from code center last time (Tom can get the program by SYNC or SUBMIT operation), Tom’s modification will be accepted. This situation means that there was no newly accepted modification on the ith line during the time from the ith line’s last accepted modification to Tom’s submission.
  3. Otherwise, if Tom’s priority is higher than the priority of the last author of the ith line, Tom’s modification will be accepted.
  4. In other cases, Tom’s modification on the ith line this time will be ignored and never be processed again.
  5. If Tom’s modification was accepted, the code center would record the modification time of the ith line as the time when Tom’s SUBMIT operation happened.

Please note that a programmer can modify multiple lines before he submits, and his modification on some lines may be accepted, but on the other lines may be ignored.

For example, Alice and Bob are two programmers. Alice’s priority is 1 and Bob’s is 2(2 is higher than 1). In following case A and B, Bob’s modification on the first line will be accepted. However, Alice’s modification will be ignored in Case C but will be accepted in Case D.

Case A
[2010/07/18 12:00:00] Alice SYNC
[2010/07/18 12:00:01] Bob SYNC
Alice and Bob are editing the first line.
[2010/07/18 12:05:00] Alice SUBMIT
[2010/07/18 12:06:00] Bob SUBMIT

Case B
[2010/07/18 12:00:00] Alice SYNC
Alice is editing the first line.
[2010/07/18 12:05:00] Alice SUBMIT
[2010/07/18 12:05:01] Bob SYNC
Bob is editing the first line
[2010/07/18 12:06:00] Bob SUBMIT

Case C
[2010/07/18 12:00:00] Alice SYNC
[2010/07/18 12:00:02]Bob SYNC
Alice and Bob are editing the first line.
[2010/07/18 12:05:00]Bob SUBMIT
[2010/07/1812:06:00]Alice SUBMIT

Case D
[2010/07/18 12:00:00] Bob SYNC
Bob is editing the first line.
[2010/07/18 12:05:00]Bob SUBMIT
[2010/07/18 12:05:01]Alice SYNC
Alice is editing the first line
[2010/07/18 12:06:00]Alice SUBMIT

You need to help Jack to figure out who is the last author of every code line in the final standard version of the program.

Input
The input contains several test cases.
For each test case, the first line contains an integer n (0<n<=10000), representing the number of programmers. The following lines contain their working details.

For each programmer, the first line contains a string and two integers pi and qi. The string represents his/her name, which only contains letters. The length of each name is less than 30. pi is his/her priority number and qi is the number of operations his/her has done. Each of the following qi lines contains a single operation. The format is as following:

“[yyyy/mm/dd hh:mm:ss] OPERATION”

There is a blank between day(dd) and hour(hh), as well as the right square bracket and OPERATION. The OPERATION has three formats: “SYNC”, “MODIFY line_id” and “SUBMIT”. The line_id was an integer representing the certain line number on which this modification happens. There is a blank between MODIFY and line_id. There is no extra blank.

The line numbers and priority numbers are integers from 0 to 231-1. The sum of all the qi is less than or equal to 50000. You can assume that all operations happen in different time.

The input file ends by a single 0 in a line.

Output
For each test case, details of each modified line should show in a line. The format is as follows:

“line_id [yyyy/mm/dd hh:mm:ss] BY name”

The line_id is the certain line which has been modified. The date shows the time of its last accepted modification and name shows the author. There’s a single white blank between line_id and the left bracket, as well as the day(dd) and hour(hh), the right bracket and “BY”, “BY” and name. Beside these, there’s no spare white blank.

The lines are sorted increasingly by line_id. At the end of each test case, there is a single line contains a word “END”.

Sample Input
2
Alice 1 3
[2010/07/18 12:00:00] SYNC
[2010/07/18 12:01:00] MODIFY 1
[2010/07/18 12:05:00] SUBMIT
Bob 2 3
[2010/07/18 12:00:01] SYNC
[2010/07/18 12:01:30] MODIFY 1
[2010/07/18 12:06:00] SUBMIT
2
Alice 1 3
[2010/07/18 12:05:01] SYNC
[2010/07/18 12:05:30] MODIFY 1
[2010/07/18 12:06:00] SUBMIT
Bob 2 3
[2010/07/18 12:00:01] SYNC
[2010/07/18 12:01:30] MODIFY 1
[2010/07/18 12:05:00] SUBMIT
0

Sample Output
1 [2010/07/18 12:06:00] BY Bob
END
1 [2010/07/18 12:06:00] BY Alice
END

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘