[Huawei OD Unified Exam B Paper | 100 points] Alarm Suppression (C++ Java Python)

topic description

Alarm suppression refers to the rule that high-priority alarms suppress low-priority alarms. After a high-priority alarm is generated, a low-priority alarm is no longer generated. Please provide the actual alarm list based on the original alarm list and alarm suppression relationship.

  • No loop inhibition occurs.
  • The alarm will not be transmitted, such as A->B, B->C, in this case A will not directly suppress C. But suppressed alarms can still suppress other low priority alarms.

enter description

The first line is the number N, indicating the number of alarm suppression relations, 0 ≤ N ≤ 120
and the next N lines, each line is two alarm IDs separated by spaces, for example: id1 id2, indicating that id1 suppresses id2, the format of the alarm ID is :

Capital letter + 0 or 1 number

The last line generates a list of alarms, and the length of the list is [1,100]

output description

List of alarms actually generated

Remark

Alarm IDs are separated by a single space

use case 1

enter

2
A B
B C
A B C D E

output

A D E

illustrate

A suppresses B, B suppresses C, and finally the actual alarm is ADE

use case 2

enter

4
F G
C B
A G
A0 A
A B C D E

output

A C D E

Guess you like

Origin blog.csdn.net/shangyanaf/article/details/132013071