10194 - Football (aka Soccer)

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

Moderator: Board moderators

Julien Cornebise
Experienced poster
Posts: 145
Joined: Sat Feb 23, 2002 2:00 am
Location: Paris, France
Contact:

Re: 10194 - Football (aka Soccer)

Post by Julien Cornebise »

kvee119 wrote:*Just a few words of mine.
*Take #6 into account: Case-insentive Lex.
So when all have the same score and names are being considered, both
a B b
a b B
are correct. Dmytro already mentioned this.
It might be a cause for stable-sort's failure.
I got AC.
Thank you for answering :)
I already used case insensitive Lex : cmpnames() (called for the sort by names in step 6.1) uses strcasecmp, wich is case insenstive.
Or did you talk about another part of the code ?

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

Finally I got accepted :-) I have bug in my function which do case-insensitive comparision....

Best reagrds
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Dmytro Chernysh
Experienced poster
Posts: 146
Joined: Sat Apr 26, 2003 2:51 am

Post by Dmytro Chernysh »

Congratulations, Dominik ! :-)
I told you that the problem had been in letters odrer, but you didn't beleave me :-)

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel »

' The team name should be treated insensitively';

does this mean "bRaziL" and "BraZIL" are the same thing?

:roll:

Ivor
Experienced poster
Posts: 150
Joined: Wed Dec 26, 2001 2:00 am
Location: Tallinn, Estonia

Post by Ivor »

Code: Select all

1) aab 0p, 0g (0-0-0), 0gd (0-0)
2) Aac 0p, 0g (0-0-0), 0gd (0-0)
3) aA 0p, 0g (0-0-0), 0gd (0-0)
4) aa 0p, 0g (0-0-0), 0gd (0-0)
5) BBa 0p, 0g (0-0-0), 0gd (0-0)
6) bbc 0p, 0g (0-0-0), 0gd (0-0)
7) Bb 0p, 0g (0-0-0), 0gd (0-0)
8) bb 0p, 0g (0-0-0), 0gd (0-0)
Anyone bothers to explain how come this is the correct lexicographic order? I have solved this problem, so I know it is correct. But why? As far as I know shorter words should precede longer ones, as in case 'aa' and 'aaa', see the dictionary. :) But this order is weird to me. I think I wouldn't have solved this problem if I hadn't accidentally messed up the order with word lengths.

Ivor
There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

Ivor
Experienced poster
Posts: 150
Joined: Wed Dec 26, 2001 2:00 am
Location: Tallinn, Estonia

Post by Ivor »

Or then again it doesn't matter... :lol: I sent the other version with shorter words first and it was accepted too. Hmm... I wonder what it was I messed up in my first solution.

Anyway, sorry for keeping up a conversation with myself, 8)
Ivor
There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

roaraujo
New poster
Posts: 7
Joined: Wed May 26, 2004 2:43 pm

10194 WA

Post by roaraujo »

Why WA in 10194?!

This is my code:

[c]#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){
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;
}[/c]

roaraujo
New poster
Posts: 7
Joined: Wed May 26, 2004 2:43 pm

10194 WA

Post by roaraujo »

Why WA in 10194?!

This is my code:

[c]#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){
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;
}[/c]

roaraujo
New poster
Posts: 7
Joined: Wed May 26, 2004 2:43 pm

Post by roaraujo »

Please, somebody gives a help!

roaraujo
New poster
Posts: 7
Joined: Wed May 26, 2004 2:43 pm

Post by roaraujo »

Please, somebody gives a help!

roaraujo
New poster
Posts: 7
Joined: Wed May 26, 2004 2:43 pm

Post by roaraujo »

Finally Acc. It was a nonsense. A k! :wink:

Junayeed
New poster
Posts: 50
Joined: Sat Oct 26, 2002 9:02 am
Location: Dhaka, Bangladesh

Post by Junayeed »

I am also getting WA. Here is my code. Please check it.

[c]Code Removed[/c]
Last edited by Junayeed on Fri Sep 24, 2004 4:36 am, edited 1 time in total.
Junayeed

Junayeed
New poster
Posts: 50
Joined: Sat Oct 26, 2002 9:02 am
Location: Dhaka, Bangladesh

Post by Junayeed »

I am waiting for ur reply people. I know the code is big.
But I know u can help me.

Thanks.
Junayeed

alu_mathics
Learning poster
Posts: 55
Joined: Sat Jan 24, 2004 9:30 pm
Location: Chittagong
Contact:

Post by alu_mathics »

do u think that this is sufficient?

return (strcmp ((char *)a, (char *)b));

Notice that should the tie-breaker be the lexographic order, it must be done case insenstive.

hope this will help you.
cuii e

Junayeed
New poster
Posts: 50
Joined: Sat Oct 26, 2002 9:02 am
Location: Dhaka, Bangladesh

Post by Junayeed »

it must be done case insenstive
Its not clear to me. Please explain it with some example.

Thanks.
Junayeed

Post Reply

Return to “Volume 101 (10100-10199)”