Page 3 of 9

Posted: Fri Sep 17, 2004 9:07 pm
by alu_mathics
MatH
math

should be treated as same.
Hope you got it.

Posted: Mon Oct 11, 2004 10:48 pm
by Abednego
Yep. Making comparisons case insensitive did the job. I missed that part at first, too.

I think this is stupid because it makes the output undefined for a case like this:

Code: Select all

2
blah
2
A
a
2
A#1@1#a
a#1@1#A
yada
2
a
A
2
A#1@1#a
a#1@1#A
My code prints

Code: Select all

blah
1) A 2p, 2g (0-2-0), 0gd (2-2)
2) a 2p, 2g (0-2-0), 0gd (2-2)

yada
1) a 2p, 2g (0-2-0), 0gd (2-2)
2) A 2p, 2g (0-2-0), 0gd (2-2)
But other outputs are also valid.

10194

Posted: Wed Apr 06, 2005 8:23 pm
by lonelyone

Code: Select all

#include <stdio.h>
#include <stdlib.h> 
#include <string.h> 
#include <strings.h>
#define lim 40 
#define lim_2 39 
#define tour 102 
#define wor 72 

int main() 
{ 
/* In the struct below, result[0] are the wins, result[1] are the ties, result[2] are the losses; goals[0] are the goals scored and goals[1] are the goals against. */ 
struct _team 
{ 
	char name[lim]; 
	int points, result[3], games, goals[2]; 
}team[lim]; 

	int n_tournaments, i, j, k, l, games, teams, score1, score2, aux; 
	char *team1, *team2, n_team[lim], word[wor], tournament[tour]; 

	scanf("%d", &n_tournaments); 
	getc(stdin); 
	for(i=0; i < n_tournaments; ++i)
	{ 
		for(j=0; j < lim; ++j)
		{ 
			team[j].games = 0; 
			team[j].points = 0; 
			for(k=0; k < 2; k++) 
				team[j].goals[k] = 0; 
				for(k=0; k < 3; ++k) 
					team[j].result[k] = 0; 
		} 
		aux = 0; 
		fgets(tournament, tour, stdin); 
		scanf("%d", &teams); 
		getc(stdin); 
		for(j=0; j < teams; ++j)
		{ 
			fgets(n_team, lim, stdin); 
			team1 = strtok(n_team, "\n"); 
			strcpy(team[j].name, team1); 
		} 
		scanf("%d", &games); 
		getc(stdin); 
		for(j=0; j < games; ++j)
		{ 
			fgets(word, wor, stdin); 
			team1 = strtok(word, "#"); 
			score1 = atoi(strtok(NULL, "@")); 
			score2 = atoi(strtok(NULL, "#")); 
			team2 = strtok(NULL, "\n"); 
			if(strcasecmp(team1, team2) != 0)
			{ 
				for(k=0; k < teams; ++k)
				{ 
					if(strcasecmp(team[k].name, team1) == 0) 
						break; 
				} 
				for(l=0; l < teams; ++l)
				{ 
					if(strcasecmp(team[l].name, team2) == 0) 
						break; 
				} 
				team[l].games++; 
				team[k].games++; 
				team[l].goals[1] += score1; 
				team[l].goals[0] += score2; 
				team[k].goals[0] += score1; 
				team[k].goals[1] += score2; 
				if(score1 < score2)
				{ 
					team[l].points += 3; /* Lose 1 and Win 2! */ 
					team[k].result[2]++; 
					team[l].result[0]++; 
				} 
				else if(score1 > score2)
				{ 
					team[k].points += 3; /* Win 1 and Lose 2! */ 
					team[l].result[2]++; 
					team[k].result[0]++; 
				} 
				else
				{ 
					team[k].points++; /* Tie between 1 */ 
					team[l].points++; /* and 2! */ 
					team[k].result[1]++; 
					team[l].result[1]++; 
				} 
			} 
		} 
		/* Calculates for to print OUTPUT */ 
		printf("%s", tournament); 
		for(k=0; k < (teams - 1); ++k)
		{ 
			for(l=k; l < teams; ++l)
			{ 
				/* Most points */ 
				if(team[k].points < team[l].points)
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
				/* Most wins */ 
				else if(team[k].points == team[l].points && team[k].result[0] < team[l].result[0])
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
				/* Most goals difference */ 
				else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) < (team[l].goals[0] - team[l].goals[1]))
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
				/* Most goals scored */ 
				else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] < team[k].goals[0])
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
				/* Less games played */ 
				else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] == team[l].goals[0] && team[k].games > team[l].games)
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
				/* Case two teams are tied, the list is appears in lexicographic order. (OBS: Use of the function strcasecmp) */ 
				else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] == team[l].goals[0] && team[k].games == team[l].games && strcasecmp(team[k].name, team[l].name) >= 0 )//&& strlen(team[k].name)<strlen(team[l].name))
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
			} 
		} 
		aux++; 
		/* Printing OUTPUT */ 
		for(j=0; j < teams; ++j)
		{ 
			printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", aux, team[j].name, team[j].points, team[j].games, team[j].result[0], team[j].result[1], team[j].result[2], (team[j].goals[0] - team[j].goals[1]), team[j].goals[0], team[j].goals[1]); 
			aux++; 
		} 
		if(i < (n_tournaments - 1)) 
			printf("\n"); 
	} 
	return 0; 
}

Could somebody do me a favor.
Thanks a million.

Posted: Sun Apr 10, 2005 10:10 am
by lonelyone

Code: Select all

#include <stdio.h>
#include <stdlib.h> 
#include <string.h> 
#include <strings.h>
#define lim 41
#define lim_2 40 
#define tour 102 
#define wor 72 

int main() 
{ 
/* In the struct below, result[0] are the wins, result[1] are the ties, result[2] are the losses; goals[0] are the goals scored and goals[1] are the goals against. */ 
struct _team 
{ 
	char name[lim]; 
	int points, result[3], games, goals[2]; 
}team[lim]; 

	int n_tournaments, i, j, k, l,m, games, teams, score1, score2, aux; 
	char *team1, *team2, n_team[lim], word[wor], tournament[tour]; 
	char previous[40];

	scanf("%d", &n_tournaments); 
	getc(stdin); 
	for(i=0; i < n_tournaments; ++i)
	{ 
		for(j=0; j < lim; ++j)
		{ 
			team[j].games = 0; 
			team[j].points = 0; 
			for(k=0; k < 2; k++) 
				team[j].goals[k] = 0; 
				for(k=0; k < 3; ++k) 
					team[j].result[k] = 0; 
		} 
		aux = 0; 
		fgets(tournament, tour, stdin); 
		scanf("%d", &teams); 
		getc(stdin); 
		for(j=0; j < teams; ++j)
		{ 
			fgets(n_team, lim, stdin); 
			team1 = strtok(n_team, "\n"); 
			strcpy(team[j].name, team1); 
		} 
		scanf("%d", &games); 
		getc(stdin); 
		for(j=0; j < games; ++j)
		{ 
			fgets(word, wor, stdin); 
			team1 = strtok(word, "#"); 
			score1 = atoi(strtok(NULL, "@")); 
			score2 = atoi(strtok(NULL, "#")); 
			team2 = strtok(NULL, "\n"); 
			if(strcasecmp(team1, team2) != 0)
			{ 
				for(k=0; k < teams; ++k)
				{ 
					if(strcasecmp(team[k].name, team1) == 0) 
						break; 
				} 
				for(l=0; l < teams; ++l)
				{ 
					if(strcasecmp(team[l].name, team2) == 0) 
						break; 
				} 
				team[l].games++; 
				team[k].games++; 
				team[l].goals[1] += score1; 
				team[l].goals[0] += score2; 
				team[k].goals[0] += score1; 
				team[k].goals[1] += score2; 
				if(score1 < score2)
				{ 
					team[l].points += 3; /* Lose 1 and Win 2! */ 
					team[k].result[2]++; 
					team[l].result[0]++; 
				} 
				else if(score1 > score2)
				{ 
					team[k].points += 3; /* Win 1 and Lose 2! */ 
					team[l].result[2]++; 
					team[k].result[0]++; 
				} 
				else
				{ 
					team[k].points++; /* Tie between 1 */ 
					team[l].points++; /* and 2! */ 
					team[k].result[1]++; 
					team[l].result[1]++; 
				} 
			} 
		} 
		/* Calculates for to print OUTPUT */ 
		printf("%s", tournament); 
		for(m=0; m < (teams - 1); ++m)
		{ 
			for(l=1; l < teams-m; ++l)
			{ 
			    k=l-1;
				/* Most points */ 
				if(team[k].points < team[l].points)
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
				/* Most wins */ 
				else if(team[k].points == team[l].points && team[k].result[0] < team[l].result[0])
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
				/* Most goals difference */ 
				else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) < (team[l].goals[0] - team[l].goals[1]))
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
				/* Most goals scored */ 
				else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] < team[k].goals[0])
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
				/* Less games played */ 
				else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] == team[l].goals[0] && team[k].games > team[l].games)
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
				/* Case two teams are tied, the list is appears in lexicographic order. (OBS: Use of the function strcasecmp) */ 
				else if(team[k].points == team[l].points && team[k].result[0] == team[l].result[0] && (team[k].goals[0] - team[k].goals[1]) == (team[l].goals[0] - team[l].goals[1]) && team[k].goals[0] == team[l].goals[0] && team[k].games == team[l].games && strcasecmp(team[k].name, team[l].name) >= 0 )//&& strlen(team[k].name)<strlen(team[l].name))
				{ 
					team[lim_2] = team[k]; 
					team[k] = team[l]; 
					team[l] = team[lim_2]; 
				} 
			} 
		} 
		aux++; 
		/* Printing OUTPUT */ 
		strcpy(previous,"");
		for(j=0; j < teams; ++j)
		{ 
		    if(strcmp(previous,team[j].name)!=0)
		    {
		    	printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", aux, team[j].name, team[j].points, team[j].games, team[j].result[0], team[j].result[1], team[j].result[2], (team[j].goals[0] - team[j].goals[1]), team[j].goals[0], team[j].goals[1]); 
		    	aux++;
            }
            strcpy(previous,team[j].name);
		} 
		if(i < (n_tournaments - 1)) 
			printf("\n"); 
	} 
	return 0; 
}
still can't accpet

Posted: Mon May 02, 2005 6:37 am
by Rocky
lonelyone
I Just Got Ac The Problem.I Do Not Compile Your Code.
But I Think You Do Some Mistake In The Term CASE INSENSITIVE.
Try With IT.

GOOD LUCK
Rocky

10194 Football -- Why WA?

Posted: Thu May 05, 2005 11:04 am
by johnnydog33
Any trick data for this problem?I got Wa all the time.

Thanks for you reply.

program p10194;
var p1,p2,len,test,sc1,sc2,j,num,v,i,team,time:integer;
cupname,st1,st2:string;
name,bname:array[1..30] of string;
ch1,ch2,ch:char;
p,g,l,w,d,s,x:array[1..30] of integer;
check1,check2:boolean;
function find(inn:string):integer;
var i:integer;
begin
for i:=1 to team do
if name=inn then begin
find:=i;
exit;
end;
end;
function small(a,b:integer):boolean;
begin
small:=false;
if (w[a]*3+d[a])<(w*3+d) then begin
small:=true;
exit;
end;
if (w[a]*3+d[a])>(w*3+d) then exit;
if w[a]<w then begin
small:=true;
exit;
end;
if w[a]>w then exit;
if (g[a]-l[a])<(g-l) then begin
small:=true;
exit;
end;
if (g[a]-l[a])>(g-l) then exit;
if g[a]<g[b] then begin
small:=true;
exit;
end;
if g[a]>g[b] then exit;
if p[a]>p[b] then begin
small:=true;
exit;
end;
if p[a]<p[b] then exit;
len:=0;
repeat
check1:=false;check2:=false;
inc(len);
ch1:=name[a][len];
ch2:=name[b][len];
if not (ch1 in ['A'..'Z']) and not (ch1 in ['a'..'z']) then exit;
if not (ch2 in ['A'..'Z']) and not (ch2 in ['a'..'z']) then begin
small:=true;
exit;
end;
if ch1 in ['a'..'z'] then begin
ch1:=chr(ord(ch1)-32);
check1:=true;
end;
if ch2 in ['a'..'z'] then begin
ch2:=chr(ord(ch2)-32);
check2:=true;
end;
if ch1<ch2 then exit;
if (ch1=ch2) and check1 and not check2 then exit;
until false;
end;
begin
readln(num);
for v:=1 to num do begin
for j:=1 to 30 do name[j]:='';
fillchar(g,sizeof(g),0);
fillchar(l,sizeof(l),0);
fillchar(w,sizeof(w),0);
fillchar(d,sizeof(d),0);
fillchar(s,sizeof(s),0);
fillchar(x,sizeof(x),0);
fillchar(p,sizeof(p),0);
readln(cupname);
readln(team);
for i:=1 to team do readln(name);
readln(time);
for i:=1 to time do begin
st1:='';
repeat
read(ch);
if ch<>'#' then st1:=st1+ch;
until ch='#';
sc1:=0;
repeat
read(ch);
if ch<>'@' then sc1:=sc1*10+ord(ch)-48;
until ch='@';
sc2:=0;
repeat
read(ch);
if ch<>'#' then sc2:=sc2*10+ord(ch)-48;
until ch='#';
st2:='';
repeat
read(ch);
st2:=st2+ch;
until eoln;
readln;
p1:=find(st1);
p2:=find(st2);
g[p1]:=g[p1]+sc1;
g[p2]:=g[p2]+sc2;
l[p1]:=l[p1]+sc2;
l[p2]:=l[p2]+sc1;
inc(p[p1]);inc(p[p2]);
if sc1>sc2 then begin
inc(w[p1]);inc(s[p2]);
end;
if sc1=sc2 then begin
inc(d[p1]);inc(d[p2]);
end;
if sc1<sc2 then begin
inc(s[p1]);inc(w[p2]);
end;
end;
for i:=1 to team do x:=i;
for i:=1 to team-1 do
for j:=i+1 to team do
if (i<>j) and small(x,x[j]) then begin
test:=x;x:=x[j];x[j]:=test;
end;
for i:=1 to team do
writeln(i,') ',name[x],' ',w[x]*3+d[x],'p, ',p[x],'g (',w[x[i]],'-',d[x[i]],'-',s[x[i]],'), ',
g[x[i]]-l[x[i]],'gd (',g[x[i]],'-',l[x[i]],')');
writeln;
end;
end.

Reply on 10194

Posted: Tue May 10, 2005 12:21 pm
by Rocky
I Can Not Understand Your Code.But The Tricky Thing Of This Problem Is CASE INSENSITIVE.DO You Thing About That.

GOOD LUCK
ROCKY

10194

Posted: Sat Nov 12, 2005 4:00 pm
by Lond
Hello!
First post here..
Well, i've been trying to correct this code, but i don't see any mistakes in it.. Could someone lend a hand?

Code: Select all

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

struct team
{
    char name[31];
    int games;
    int goalsA;
    int goalsDif;
    int goalsS;
    int points;
    int losses;
    int ties;
    int wins;
};
   
int timesCmp (const void *i, const void *j);

int main (void)
{
    int g,n,t,i,j,k,maior,tempI[2];
    char tournament[101],temp[3][31];
    struct team *teams;

    scanf("%d",&n);
    getchar();
    for ( i = 0 ; i < n ; i++ )
    {
        tempI[0] = tempI[1] = 0;
        scanf("%100[^\n]",tournament);
        scanf(" %d",&t);
        getchar();
        teams = (struct team *) malloc ( t * sizeof(struct team));
        if (!teams) return 1;
       
        for ( j = 0 ; j < t ; j++ )
        {
            teams[j].goalsDif = teams[j].points = teams[j].games = teams[j].goalsA = teams[j].goalsS = teams[j].losses = teams[j].ties = teams[j].wins = 0;
           
            scanf("%30[^\n]",teams[j].name);
            getchar();
        }
       
        scanf("%d",&g);
        getchar();
        for ( j = 0 ; j < g && j < 1000; j++)
        {
           
            /* Get the first team name */
            scanf("%30[^#]",temp[0]);
            getchar();

            /* Get the first team Goals */
            scanf("%2[^@]",temp[2]);
            getchar();
            tempI[0] = atoi(temp[2]);
           
            /* Get the second team Goals */
            scanf("%2[^#]",temp[2]);
            getchar();
            tempI[1] = atoi(temp[2]);
           
            /* Get the second team name */
            scanf("%30[^\n]",temp[1]);
            getchar();

            if ( tempI[0] > tempI[1] )
            {
                maior = 0;
            }
            else if ( tempI[0] < tempI[1] )
            {
                maior = 1;
            }
            else
            {
                maior = -1;
            }
           
            for ( k = 0 ; k < t ; k++ )
            {
                    if ( strcmp(temp[0],teams[k].name) == 0 )
                    {
                        teams[k].goalsS += tempI[0];
                        teams[k].goalsA += tempI[1];
                        teams[k].goalsDif += tempI[0];
                        teams[k].goalsDif -= tempI[1];
                        if ( !maior )
                        {
                            teams[k].wins++;
                            teams[k].points += 3;
                        }
                        else if ( maior == 1 )
                        {
                            teams[k].losses++;
                        }
                        else
                        {
                            teams[k].ties++;
                            teams[k].points++;
                        }
                        teams[k].games++;
                        break;
                    }
            }
           
            for ( k = 0 ; k < t ; k++ )
            {
                    if ( strcmp(temp[1],teams[k].name) == 0 )
                    {
                        teams[k].goalsS += tempI[1];
                        teams[k].goalsA += tempI[0];
                        teams[k].goalsDif += tempI[1];
                        teams[k].goalsDif -= tempI[0];
                        if ( maior == 1)
                        {
                            teams[k].wins++;
                            teams[k].points += 3;
                        }
                        else if ( !maior )
                        {
                            teams[k].losses++;
                        }
                        else
                        {
                            teams[k].ties++;
                            teams[k].points++;
                        }
                        teams[k].games++;
                        break;
                    }
            }
        }
       
        qsort(teams , t , sizeof(struct team) , timesCmp);
       
        printf("%s\n",tournament);       
        for ( j = 0 ; j < t ; j++ )
        {
            printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)",j+1,teams[j].name,teams[j].points,teams[j].games,teams[j].wins,teams[j].ties,teams[j].losses,teams[j].goalsDif,teams[j].goalsS,teams[j].goalsA);
            if ( j != t-1 )
            {
                printf("\n");
            }
        }
        if ( i != n-1 )
        {
            printf("\n\n");
        }
        else
        {
	        printf("\n");
        }
    }
   
    return 0;
}

int timesCmp (const void *i, const void *j)
{
    struct team *a,*b;
    a = (struct team *)i;
    b = (struct team *)j;
    if ( a->points > b->points )
    {
        return -1;
    }
    else if ( a->points == b->points )
    {
        if ( a->wins > b->wins )
        {
            return -1;
        }
        else if ( a->wins == b->wins )
        {
            if ( a->goalsDif > b->goalsDif )
            {
                return -1;
            }
            else if ( a->goalsDif == b->goalsDif )
            {
                if ( a->goalsS > b->goalsS )
                {
                    return -1;
                }
                else if ( a->goalsS == b->goalsS )
                {
                    if ( a->games > b->games )
                    {
                        return 1;
                    }
                    else if ( a->games == b->games )
                    {
	                    return strcasecmp(a->name,b->name);
                    }
                    else
                    {
                        return -1;
                    }
                }
                else
                {
                    return 1;
                }
            }
            else
            {
                return 1;
            }
        }
        else
        {
            return 1;
        }
    }
    else
    {
        return 1;
    }
}
Thanks

Runtime Error (SIGSEGV)

Posted: Sat Nov 12, 2005 9:53 pm
by tan_Yui
Hi, everyone.
I got the Judgement 'Runtime Error (SIGSEGV)' several times.
I want to know the cause of this error.
Here is my code.
Please help....

Code: Select all

/* @JUDGE_ID:  *******  10194  C */
#include<stdio.h>
#include<string.h>
#include<stdlib.h> /* qsort */
#include<ctype.h> /* tolower */
#define NAME_LENGTH 33

struct info {
  char name[NAME_LENGTH], temp_name[NAME_LENGTH];
  int points;
  int games;
  int wins;
  int ties;
  int losses;
  int difference;
  int scored;
  int against;
};

struct info team[30];

int cmp(const void *e1, const void *e2) {
  struct info a, b;

  a = *((const struct info *)e1);
  b = *((const struct info *)e2);

  if (a.points < b.points) return 1;
  else if (a.points > b.points) return -1;
  else if (a.wins < b.wins) return 1;
  else if (a.wins > b.wins) return -1;
  else if (a.difference < b.difference) return 1;
  else if (a.difference > b.difference) return -1;
  else if (a.scored < b.scored) return 1;
  else if (a.scored > b.scored) return -1;
  else if (a.games > b.games) return 1;
  else if (a.games < b.games) return -1;
  else if (strcmp(a.temp_name, b.temp_name)>0) return 1;
  else if (strcmp(a.temp_name, b.temp_name)<0) return -1;
  else return 0;
}

main() {
  int N, T, G;
  int set, i, j, len;
  int score1, score2, n1, n2;
  char tournament[101], team1[NAME_LENGTH], team2[NAME_LENGTH];

  scanf("%d\n", &N);
  for(set=N; set>0; set--) {
    if(set!=N) printf("\n");

    gets(tournament);
    scanf("%d\n", &T);
    for(i=0; i<T; i++) {
      gets(team[i].name);
      len = strlen(team[i].name);
      for(j=0; j<len; j++) team[i].temp_name[j] = tolower(team[i].name[j]);
      team[i].temp_name[len] = '\0';

      team[i].points = team[i].games = team[i].wins = team[i].ties = 0;
      team[i].losses = team[i].scored = team[i].against = 0;
    }
    scanf("%d\n", &G);
    for(i=0; i<G; i++) {
      scanf("%[^#]#%d@%d#%[^\n]\n", team1, &score1, &score2, team2); 

      /* search the team name from database */
      for(j=0; j<T; j++) {
        if(strcmp(team1, team[j].name)==0) {
          n1 = j;
          break;
        }
      }
      for(j=0; j<T; j++) {
        if(strcmp(team2, team[j].name)==0) {
          n2 = j;
          break;
        }
      }

      /* put the info of the game into the database */
      team[n1].games++;
      team[n2].games++;
      team[n1].scored += score1;
      team[n2].scored += score2;
      team[n1].against += score2;
      team[n2].against += score1;
      if(score1>score2) {
        team[n1].wins++;
        team[n2].losses++;
        team[n1].points += 3;
      }
      else if(score1<score2) {
        team[n2].wins++;
        team[n1].losses++;
        team[n2].points += 3;
      }
      else {
        team[n1].ties++;
        team[n2].ties++;
        team[n1].points++;
        team[n2].points++;
      }
    }
    for(i=0; i<G; i++) {
      team[i].difference = team[i].scored - team[i].against;
    }
    qsort(team, T, sizeof(struct info), cmp);

    /* outputs the result of sorting */
    printf("%s\n", tournament);
    for(i=0; i<T; i++) {
      printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", i+1, team[i].name, team[i].points, team[i].games, team[i].wins, team[i].ties, team[i].losses, team[i].difference, team[i].scored, team[i].against);
    }
  }
  return 0;
}
Best regards.

10194 by build in q-sort

Posted: Thu Nov 24, 2005 11:15 am
by Tanu
Is my function OK ....
I'm getting wrong answer...
Plz help

Code: Select all


int comp(const void *a, const void *b)
{
	st *x=(st *)a;
	st *y=(st *)b;

	if(x->pointEarned > y->pointEarned)	return 1;
	if(x->pointEarned <= y->pointEarned)	return -1;

	if(x->wins > y->wins)	return 1;
	if(x->wins < y->wins)	return -1;

	if(x->goalDiff > y->goalDiff)	return 1;
	if(x->goalDiff < y->goalDiff)	return -1;

	if(x->goalScored > y->goalScored)	return 1;
	if(x->goalScored < y->goalScored)	return -1;

	if(x->gamePlayed > y->gamePlayed)	return -1;
	if(x->gamePlayed < y->gamePlayed)	return 1;

	return strcmp(y->name,x->name);
}

Tanu

about q-sort

Posted: Thu Nov 24, 2005 3:46 pm
by Rocky
As i remember this problem is ok by built in qsort but you do some wrong here.that is you need to sort the input by pointearned ,if pointearned is equal then by win,if win is equal then.... and so on.
i give some modification to your code now try..

Code: Select all


int comp(const void *a, const void *b) 
{ 
   st *x=(st *)a; 
   st *y=(st *)b; 

   if(x->pointEarned != y->pointEarned) 
      return(y->pointEarned - x->pointEarned); // the highest point come frist

   if(x->wins != y->wins) 
     return(y->wins - x->wins); //highest win come frist

   if(x->goalDiff != y->goalDiff) 
     return (y->goalDiff - x->goalDiff); //highest goaldiff come frist

   if(x->goalScored != y->goalScored)  
    return(y->goalScored - x->goalScored); //highest goalscored come frist

   if(x->gamePlayed != y->gamePlayed) 
     return(x->gamePlayed - y->gamePlayed); //less gameplayed come frist

   return strcmp(x->name,y->name); 
} 


now try

GOOD LUCK
Rocky

Posted: Sun Dec 11, 2005 2:59 am
by tan_Yui
Anyone can help me for above my post?
I want to know why my code get RuntimeError.

Thank you.

Posted: Tue Feb 21, 2006 5:12 pm
by Ming Han
They won't give you 'A' and 'a' because all the team names are unique.

Posted: Sat Mar 11, 2006 3:34 pm
by deepdish
I post your C code and got AC, XD

10194 CE (UVa) and WA (Programming Challenges) in Java

Posted: Wed May 17, 2006 5:56 am
by guiper26
The site os this problem is http://acm.uva.es/p/v101/10194.html
I solved this problem in C. Now I