10194 - Football (aka Soccer)

All about problems in Volume CI. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

10194

Postby lonelyone » Wed Apr 06, 2005 8:23 pm

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.
lonelyone
Learning poster
 
Posts: 65
Joined: Sat Feb 19, 2005 6:53 pm

Postby lonelyone » Sun Apr 10, 2005 10:10 am

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
lonelyone
Learning poster
 
Posts: 65
Joined: Sat Feb 19, 2005 6:53 pm

Postby Rocky » Mon May 02, 2005 6:37 am

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
User avatar
Rocky
Experienced poster
 
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

10194 Football -- Why WA?

Postby johnnydog33 » Thu May 05, 2005 11:04 am

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[i]=inn then begin
find:=i;
exit;
end;
end;
function small(a,b:integer):boolean;
begin
small:=false;
if (w[a]*3+d[a])<(w[b]*3+d[b]) then begin
small:=true;
exit;
end;
if (w[a]*3+d[a])>(w[b]*3+d[b]) then exit;
if w[a]<w[b] then begin
small:=true;
exit;
end;
if w[a]>w[b] then exit;
if (g[a]-l[a])<(g[b]-l[b]) then begin
small:=true;
exit;
end;
if (g[a]-l[a])>(g[b]-l[b]) 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[i]);
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]:=i;
for i:=1 to team-1 do
for j:=i+1 to team do
if (i<>j) and small(x[i],x[j]) then begin
test:=x[i];x[i]:=x[j];x[j]:=test;
end;
for i:=1 to team do
writeln(i,') ',name[x[i]],' ',w[x[i]]*3+d[x[i]],'p, ',p[x[i]],'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.
johnnydog33
New poster
 
Posts: 10
Joined: Mon Mar 14, 2005 7:35 am

Reply on 10194

Postby Rocky » Tue May 10, 2005 12:21 pm

I Can Not Understand Your Code.But The Tricky Thing Of This Problem Is CASE INSENSITIVE.DO You Thing About That.

GOOD LUCK
ROCKY
User avatar
Rocky
Experienced poster
 
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

10194

Postby Lond » Sat Nov 12, 2005 4:00 pm

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
Always look the bright side of life ;)
Lond
New poster
 
Posts: 1
Joined: Sat Nov 12, 2005 3:51 pm

Runtime Error (SIGSEGV)

Postby tan_Yui » Sat Nov 12, 2005 9:53 pm

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.
tan_Yui
Experienced poster
 
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

10194 by build in q-sort

Postby Tanu » Thu Nov 24, 2005 11:15 am

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
User avatar
Tanu
Learning poster
 
Posts: 70
Joined: Sun May 29, 2005 12:46 pm
Location: Mars

about q-sort

Postby Rocky » Thu Nov 24, 2005 3:46 pm

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
User avatar
Rocky
Experienced poster
 
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

Postby tan_Yui » Sun Dec 11, 2005 2:59 am

Anyone can help me for above my post?
I want to know why my code get RuntimeError.

Thank you.
tan_Yui
Experienced poster
 
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

Postby Ming Han » Tue Feb 21, 2006 5:12 pm

They won't give you 'A' and 'a' because all the team names are unique.
:: HanWorks ::
User avatar
Ming Han
Learning poster
 
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore

Postby deepdish » Sat Mar 11, 2006 3:34 pm

I post your C code and got AC, XD
deepdish
New poster
 
Posts: 3
Joined: Mon Jan 31, 2005 4:14 pm

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

Postby guiper26 » Wed May 17, 2006 5:56 am

The site os this problem is http://acm.uva.es/p/v101/10194.html
I solved this problem in C. Now I
guiper26
New poster
 
Posts: 1
Joined: Wed May 17, 2006 5:22 am

10194

Postby mohsincsedu » Fri Sep 01, 2006 8:23 pm

I submit my code in c, then C++
every time result is compile error.
but why???

I run my code in Fedora Core (5) but there compile my code
what's happen??????

Here is my code:
Code: Select all



Sorry for posting my big code..................


Thanks in advanced.
Amra korbo joy akhdin............................
mohsincsedu
Learning poster
 
Posts: 63
Joined: Tue Sep 20, 2005 12:31 am
Location: Dhaka

Postby beloni » Mon Nov 20, 2006 9:34 pm

hello, I really dont know what to do anymore. I received WA for several times...

Code: Select all

#include <iostream>
#include <cstring>
#include <strings.h>
#include <cstdlib>

#define TOUR_LEN 101
#define TEAM_LEN 31

/* status */
/*#define RK   0*/
#define PT   1
#define GP   2
#define W   3
#define T   4
#define L   5
#define GD   6
#define GS   7
#define GA   8

using namespace std;


struct Team
{
   char name[TEAM_LEN];
   int stat[9];
   Team();
};

Team::Team()
{
   for( int i(0); i < 9; i++ )
      stat[i] = 0;
}


int getindex( const char *name, Team *t, int len )
{
   for( int i(0); i < len; i++ )
      if( strcmp( t[i].name, name ) == 0 )
         return i;
   return -1;
}


void game_parser( const char *game, Team *t, int len )
{
   char name[2][TEAM_LEN];
   char res[2][3];
   int flag(0), j(0);
   for( int i(0); game[i]; i++ )
   {
      if( flag == 0 )
      {
         if( game[i] == '#' ) /* first name ends */
         {
            flag = 1;
            name[0][j] = 0;
            j = 0;
         }
         else
         {
            name[0][j] = game[i];
            j++;
         }         
      }
      else if( flag == 1 )
      {
         if( game[i] == '@' ) /* first result ends */
         {
            flag = 2;
            res[0][j] = 0;
            j = 0;
         }
         else
         {
            res[0][j] = game[i];
            j++;
         }
      }
      else if( flag == 2 )
      {
         if( game[i] == '#' ) /* second result ends */
         {
            flag = 3;
            res[1][j] = 0;
            j = 0;
         }
         else
         {
            res[1][j] = game[i];
            j++;
         }
      }
      else
      {
         name[1][j] = game[i];
         j++;
      }
   }
   name[1][j] = 0;

   int ind0( getindex(name[0], t, len) ), ind1( getindex(name[1], t, len) );
   int g0( atoi(res[0]) ), g1( atoi(res[1]) );

// scores
   t[ind0].stat[GS] += g0;
   t[ind0].stat[GA] += g1;
   t[ind0].stat[GD] += g0 - g1;

   t[ind1].stat[GS] += g1;
   t[ind1].stat[GA] += g0;
   t[ind1].stat[GD] += g1 - g0;

// points W T L
   if( g0 > g1 )
   {
      t[ind0].stat[PT] += 3;
      t[ind0].stat[W]++;
      t[ind1].stat[L]++;
   }
   else if( g0 < g1 )
   {
      t[ind1].stat[PT] += 3;
      t[ind1].stat[W]++;
      t[ind0].stat[L]++;
   }
   else
   {
      t[ind0].stat[PT]++;
      t[ind0].stat[T]++;
      t[ind1].stat[PT]++;
      t[ind1].stat[T]++;
   }

// games played
   t[ind0].stat[GP]++;
   t[ind1].stat[GP]++;
}      


void print( Team *t )
{
   cout << t->name << ' '
         << t->stat[PT] << "p, " << t->stat[GP]   << "g ("
         << t->stat[W] << '-' << t->stat[T] << '-' << t->stat[L] << "), "
         << t->stat[GD] << "gd (" << t->stat[GS] << '-' << t->stat[GA] << ")\n";
}


int ascmp(const void *a, const void *b)
{
   Team *x = (Team *)a;
   Team *y = (Team *)b;

   if(x->stat[PT] != y->stat[PT])
      return(y->stat[PT] - x->stat[PT]);

   if(x->stat[W] != y->stat[W])
     return(y->stat[W] - x->stat[W]);

   if(x->stat[GD] != y->stat[GD])
     return (y->stat[GD] - x->stat[GD]);

   if(x->stat[GS] != y->stat[GS])
    return(y->stat[GS] - x->stat[GS]);

   if(x->stat[GP] != y->stat[GP])
     return(x->stat[GP] - y->stat[GP]);

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

/*int ascmp( const void *y, const void *x )
{
   Team *a( (Team *)y );
   Team *b( (Team *)x );

   if( a->stat[PT] > b->stat[PT] ) return -1;
   else if( a->stat[PT] < b->stat[PT] ) return 1;
   else
   {
      if( a->stat[W] > b->stat[W] ) return -1;
      else if( a->stat[W] < b->stat[W] ) return 1;
      else
      {
         if( a->stat[GD] > b->stat[GD] ) return -1;
         else if( a->stat[GD] < b->stat[GD] ) return 1;
         else
         {
            if( a->stat[GS] > b->stat[GS] ) return -1;
            else if( a->stat[GS] < b->stat[GS] ) return 1;
            else
            {
               if( a->stat[GP] > b->stat[GP] ) return -1;
               else if( a->stat[GP] < b->stat[GP] ) return 1;
               else return strcasecmp( a->name, b->name );
            }
         }
      }
   }
}*/
               
                  

int main()
{
   int ntour, nteam, gp;
   char tour_name[TOUR_LEN], game_buff[1000];
   Team *teams(0);

   cin >> ntour; cin.get();
   while( ntour-- )
   {
      cin.getline( tour_name, TOUR_LEN );
      cin >> nteam; cin.get();

      teams = new Team[nteam];
      for( int i(0); i < nteam; i++ )
         cin.getline( teams[i].name, TEAM_LEN );
      
      cin >> gp; cin.get();
      for( int i(0); i < gp; i++ )
      {
         cin.getline( game_buff, 1000 );
         game_parser( game_buff, teams, nteam );
      }

      qsort( teams, nteam, sizeof(Team), ascmp );

      cout << tour_name << '\n';      
      for( int i(0); i < nteam; i++ )
      {
         cout << i+1 << ") ";
         print( &teams[i] );
      }

      delete[] teams;
      if( ntour ) cout << '\n';
   }
   return 0;
}


thanks for help
"A machine can do the work of fifty ordinary men, but no machine can do the work of one extraordinary man.", Shahriar Manzoor
beloni
Learning poster
 
Posts: 66
Joined: Thu Jan 05, 2006 1:41 pm
Location: Pelotas, RS, Brazil

PreviousNext

Return to Volume CI

Who is online

Users browsing this forum: No registered users and 0 guests