In this post i will share the problem that i can solve. It is Soccer Leagues.

Soccer Leagues

Time limit: 2000 ms

Memory limit: 65536 KB

 

Description

In soccer, all the major national leagues are conducted in the following way: A league consists of several teams. Over the course of a year, each team must play exactly two matches against each of the other teams – one at its own stadium and one at the opponent’s stadium. When a team plays at its own stadium, it is called the “home team” and its opponent is called the “away team”. Each match ends in one of three possible results: a home team victory, a draw, or an away team victory. Each time a team wins, it is awarded 3 points. When there’s a draw, both teams are awarded 1 point. No points are awarded for a loss. The overall ranking of the teams is based on the total number of points received by each team.

Input Format

First line contains an integer N (2 <= N <= 50), the number of teams. You are given matches definition in the form of N lines, each containing N columns. The j-th column of the i-th row of this match definition denotes the result of the match between team i and team j at team i’s stadium. ‘W’ represents a home team victory, ‘D’ represents a draw, and ‘L’ represents an away team victory. All characters on the main diagonal will be ‘-‘ because a team never plays against itself.

Output Format

N integers separated by a space, the points of each team.

 

Sample Input 1

3
-WW
W-W
WW-

Sample Output 1

6 6 6

Note

There are 3 teams in the league, and in all matches the home team has won.

 

Sample Input 2

3
-DD
L-L
WD-

Sample Output 2

5 2 8

Note

This time, the first team has 1 win and 2 draws, the second one has 2 draws and the third has 2 wins and 2 draws.

 

Sample Input 3

5
-DWWD
L-WLL
DD-WD
DDL-L
DDLL-

Sample Output 3

14 7 12 8 10

 

Sample Input 4

20
-LWWLWDLDWWWWWWDDWDW
D-WWLDDWDWDLWDDWLWDD
LL-DLDWDLDLDWWWLWDDW
LDD-LLLDLWLWWWWDWDWL
LWWW-DWDLWDWDWWWDWDW
DLLWD-WWLLDDDLWWDWWW
WWLWDL-LLDWWWWWDWWLW
LLLLLDW-LDLWDDLLLDWL
DWWWWDDD-DWWWWDWWWDW
WWWWLLLWL-LWWWWWLWWW
DWWWWWWWLW-WDWWWWWWW
DDDLLLDWWWL-DDWDWLDD
LWLWLDLLLDLW-DDDWWDD
LLWWLWDDLWLWL-WWWDLL
WWWWLLDDDWLWDD-WWWLW
DLDLLLWWLLLWWLW-DWLL
DLWWWLDLWWDWWDWL-WWD
LLDDLLWLLWLWLDLWW-WW
LLWLLLWWLWLWWDWWLD-W
LLWDLWDWDWLLWWDDWWL-

Sample Output 4

72 62 41 41 83 63 53 35 86 50 90 32 34 41 45 36 51 32 51 45

 

 

SOLUTION

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int N,i,j,tempVal = 0;
    scanf("%d",&N);
    if(N>=2 && N <=50){
        char temp[N][N];
        double length,counter1;
        int result[N];
        for(i=0;i<N;i++){
            fflush(stdin);
            scanf("%s",&temp[i]);
            result[i] = 0;
        }
        for(i = 0 ; i < N; i++){
            for(j = 0 ; j < N; j++){
                if (i != j){

                    if(temp[i][j] == 'W' || temp[i][j] == 'w'){
                            result[i] +=3;
                            result[j] += 0;

                    }
                    else if(temp[i][j] == 'L' || temp[i][j] == 'l'){
                            result[i] +=0;
                            result[j] +=3;
                    }
                    else if(temp[i][j] == 'D' || temp[i][j] == 'd'){
                        result[i] +=1;
                        result[j] +=1;
                    }
                }
            }
        }
        for(i = 0;i<N ; i++){
                printf("%d",result[i]);
                if(i!=N-1){
                 printf(" ");
                }
                else{
                        printf("\n");
                }

        }
    }
    return 0;
}
Programming Problem Test #Soccer Leagues

Leave a Reply