On the completely fair and democratic planet Equalia, everyone was treated equally. The people worked together as one, making decisions as a united group. Their way of life was so perfect that the Intergalactic Association of Habitable Planets (IAHP) decided to tell them the truth - they were not alone in the universe. The IAHP even invited them to join their group.
But there was a problem: Equalia needed to pick one person to represent them. Since no one had personal ambitions, they decided to select their representative using a multi-step, pseudo-random process.
The entire population was considered, and n candidates were shortlisted through some ritual.
The n candidates were seated in a circular table, with each seat having a fixed position, but the candidates were placed in a random order.
Figure 1. An Example Round Table
3. A randomly chosen candidate C₀ was given the Scepter of Selection (a token).
4. Three factors were determined:
Dᵢ → The direction of token passing (clockwise or counterclockwise). (For example, in Figure 1, D0 is selected as clockwise)
Sᵢ → The stopping candidate, selected from the seated candidates. (For example, in Figure 1, S0 is selected as 6)
Pᵢ → The power-up candidate, selected from the seated candidates. (For example, in Figure 1, P0 is selected as 3)
5. The token was passed from C₀ to Sᵢ, following direction Dᵢ, moving one candidate at a time. No candidates between Cᵢ and Pᵢ were skipped; all received the token.
For example, in Figure 1, candidates in Seats 1,2,3,4,5 and 6 received the token.
6. Each candidate had an initial power-up score of 0. Whenever the token passed through Pᵢ, their power-up score increased by 1.
For example, in Figure 1, candidate in Seat 3 is chosen as Pi. This candidate’s power-up score is increased to 1.
7. When the token reached Sᵢ, that candidate was eliminated. The next candidate in line (based on the passing direction) became the new starting candidate Cᵢ.
For example, in Figure 1, candidate in Seat 6 is chosen as Si. This candidate is eliminated after getting the token. The token is passed to the candidate in Seat 7, who becomes the new starting candidate.
8. Steps 4 to 7 were repeated until only one candidate remained.
Once only one candidate remained, a final score was assigned to each candidate:
Final Score=(number of times the candidate received the token) × (power-up score)
A candidate received the token if:
They were passing it.
They were the last to receive it before elimination.
They were the initial candidate at the start of a round.
If a single candidate had the highest final score, they were declared the winner.
If multiple candidates had the highest final score, a secondary selection was performed:
The names of the finalists were sorted alphabetically.
Each finalist was assigned a serial number (from 1 to f, where f is the number of finalists).
Example:
Let’s say there are 3 candidates who remained: CCC, AAA and DDD.
Their names were sorted and they were assigned serial numbers as follows:
AAA: 1
CCC: 2
DDD: 3
Each finalist voted for another finalist (not themselves) to be the representative.
A vote score was assigned:
Vote Score=(number of votes received)×(serial number assigned in Step 2)The finalist with the highest vote score won.
Example:
With reference to the example for (2),
Let AAA vote for DDD
CCC for AAA
and DDD for CCC.
Each candidate received 1 vote each.
However, Vote Score of AAA = 1*1 = 1
CCC = 1*2 = 2
DDD = 1*3 = 3
Hence, DDD is the winner.
If there was still a tie, a random candidate among the highest scorers was chosen.
Write a C program to implement this voting process. The program should:
Take n (number of candidates) as input.
Accept names of each candidate as input.
Use a doubly linked list to implement the token-passing mechanism and elimination process.