Cricket Tournament

Cricket Tournament  

Problem:

TCS NQT The program must accept the list of team names participating in a cricket tournament. The character q or Q in the input represents the end of the team list. Each team must play exactly one game against the other teams. The program must print the string value "Total Matches: " followed by the total number of matches possible excluding the semi-final and the final. Then the program must print the pairing of teams in the order of their occurrence as the output. 

Boundary Condition(s): 

3 <= Number of teams <= 12 

Input Format: 

The lines, each contains a string value representing the team name participating in a cricket tournament. 

Output Format: 

The first line contains the string value "Total Matches: " followed by the total number of matches possible excluding the semi-final and the final. The lines from the 2nd line containing the pairing of teams in the order of their occurrence 

Example Input/Output 1: 

Input: 

Chennai 

Mumbai 

Delhi 

Kolkata 

Output: 

Total Matches: 6 

Chennai vs Mumbai 

Chennai vs Delhi 

Chennai vs Kolkata 

Mumbai vs Delhi 

Mumbai vs Kolkata 

Delhi vs Kolkata 

Example Input/Output 2: 

Input: 

Mumbai 

Chennai 

Hyderabad 

Bangalore 

Kolkata 

Output: 

Total Matches: 10 

Mumbai vs Chennai 

Mumbai vs Hyderabad 

Mumbai vs Bangalore 

Mumbai vs Kolkata 

Chennai vs Hyderabad 

Chennai vs Bangalore 

Chennai vs Kolkata 

Hyderabad vs Bangalore 

Hyderabad vs Kolkata 

Bangalore vs Kolkata

Program:

l = []

while 1: 

    s = input().strip()

    if s == 'q' or s == 'Q':

        break 

    l.append(s)

k = sum(list(range(1,len(l))))

print("Total Matches:",k)

for i in range(len(l)):

    for j in range(i+1,len(l)):

        print(l[i],"vs",l[j])

Comments

Popular posts from this blog

Pronic Integers in N - InfyTQ question

Count Strong Points - Accenture

Grouping Colorful LEDs - Accenture