Questions
Selected practice problems and challenges for Competitive Programming II.
1. 19A - World Football Cup
Solve 19A - World Football Cup.
2. 235B - Let's Play Osu!
Solve 235B - Let's Play Osu!.
3. Student Management Portal
Develop a student management portal in C++. The portal stores a list of student IDs and supports the following queries:
Register ID: AddIDto the list.Search ID: PrintFOUNDifIDexists; otherwise, printNOT FOUND.Remove duplicates: Remove duplicate IDs from the list.Delete ID: Delete the first occurrence ofIDif it exists.
Commands are case-insensitive. After each query, print the current list of IDs. For a search query, print the search result before the list.
Input
The first line contains an integer T, the number of queries. Each of the next T lines contains one query.
Output
For each query, print the required result and the current list of IDs as described above.
Sample Input
10
Register 101
Register 102
Register 101
Search 102
Remove duplicates
Register 103
delete 101
Search 101
Register 104
delete 105Sample Output
101
101 102
101 102 101
FOUND
101 102 101
101 102
101 102 103
102 103
NOT FOUND
102 103
102 103 104
102 103 1044. CPU Task Scheduler
A CPU has tasks to execute. Each task has an ID, priority, and execution time.
If tasks have the same priority, they execute in First In First Out (FIFO) order. The CPU always executes the highest priority task first.
Determine:
- The order in which the tasks are executed
- The total time taken
- The completion time of each task
Input
The first line contains an integer , the number of tasks. Each of the next lines contains three space-separated integers representing the task ID, priority, and execution time.
Output
Print the execution order with the completion time of each task, followed by the total time taken.
Sample Input
6
1 3 4
2 1 2
3 4 6
4 2 5
5 4 3
6 1 7Sample Output
Execution Order:
Task 3 completes at 6
Task 5 completes at 9
Task 1 completes at 13
Task 4 completes at 18
Task 2 completes at 20
Task 6 completes at 27
Total time = 275. Minimum Swaps to Sort Employee IDs
A company stores employee IDs in an array. You are allowed to swap only adjacent elements. Find the minimum number of adjacent swaps required to arrange the IDs in ascending order.
Input
The first line contains an integer , the number of employee IDs. The second line contains space-separated integers representing the employee IDs.
Output
Print the state of the array after each adjacent swap, followed by the minimum number of adjacent swaps required on the final line.
Sample Input
5
5 1 4 2 3Sample Output
1 5 4 2 3
1 4 5 2 3
1 4 2 5 3
1 4 2 3 5
1 2 4 3 5
1 2 3 4 5
66. Robot Navigation
A robot starts at position (0, 0) on a 2D grid. You are given a string containing movement commands:
L: Move one step left ()R: Move one step right ()U: Move one step up ()D: Move one step down ()
The robot executes the commands one by one. Determine the robot's final coordinates (x, y) and whether the robot visited any coordinate more than once (including the starting position (0, 0)).
Print Yes if any position was visited more than once; otherwise, print No.
Input
Each line of input contains a non-empty string consisting of the characters L, R, U, and D.
Output
For each test case, print the final coordinates in the format (x, y) on the first line, followed by Yes or No on the second line.
Sample Input
UURR
LR
LDRLDUSample Output
(2, 2)
No
(0, 0)
Yes
(-1, -1)
Yes