10194 - Football (aka Soccer)
Moderator: Board moderators
-
- New poster
- Posts: 19
- Joined: Thu May 20, 2010 8:58 am
Re: 10194 - Football (aka Soccer)
pretty easy problem bt every1 should read the problem description carefully
one day...
-
- New poster
- Posts: 5
- Joined: Sat Aug 14, 2010 10:31 pm
Re: 10194 - Football (aka Soccer)
The code below gives me WA.
I've already did case insensitive string comparisons, but got no joy.
Every given input seems to give me correct answer.
I've already did case insensitive string comparisons, but got no joy.
Every given input seems to give me correct answer.
Code: Select all
#include <iostream>
#include <algorithm>
#define TEAMNAME 31
#define MAXLINE 70
using namespace std;
struct Team {
int points;
int wins;
int goalsScored;
int goalsAgainst;
int losses;
int gamesPlayed;
char name[TEAMNAME];
};
Team * locateTeam( Team * teams, char * teamName) {
int i = 0;
while (strcmp(teams[i].name, teamName) != 0 ) {
i++;
}
return teams + i;
}
void parseGame(char * encodedGame, Team teams[]) {
// First team
char * tok = strtok(encodedGame, "#");
Team * firstTeam = locateTeam(teams, tok);
// First team score
tok = strtok(NULL, "@");
int firstTeamScore = atoi(tok);
// Second team score
tok = strtok(NULL, "#");
int secondTeamSocre = atoi(tok);
//Second team
tok = strtok(NULL, "#");
Team * secondTeam = locateTeam(teams, tok);
Team * winner = NULL;
Team * loser = NULL;
if ( firstTeamScore > secondTeamSocre ) {
winner = firstTeam;
loser = secondTeam;
} else if ( secondTeamSocre > firstTeamScore ){
winner = secondTeam;
loser = firstTeam;
}
// Has a winner?
if (winner) {
winner->points += 3;
winner->wins += 1;
loser->losses += 1;
} else {
firstTeam->points += 1;
secondTeam->points += 1;
}
// Update scores
firstTeam->goalsScored += firstTeamScore;
firstTeam->goalsAgainst += secondTeamSocre;
secondTeam->goalsAgainst += firstTeamScore;
secondTeam->goalsScored += secondTeamSocre;
// Games played
firstTeam->gamesPlayed++;
secondTeam->gamesPlayed++;
}
void initializeTeam(Team& team, char * teamName) {
strcpy(team.name, teamName);
team.points = 0;
team.wins = 0;
team.goalsScored = 0;
team.goalsAgainst = 0;
team.losses = 0;
team.gamesPlayed = 0;
}
bool compareTeams(Team a, Team b) {
if ( a.points > b.points ) {
return true;
} else if ( a.points < b.points ) {
return false;
}
if ( a.wins > b.wins ) {
return true;
} else if ( a.wins < b.wins ) {
return false;
}
int aGd = a.goalsScored - a.goalsAgainst;
int bGd = b.goalsScored - b.goalsAgainst;
if ( aGd > bGd ) {
return true;
} else if ( aGd < bGd ) {
return false;
}
if ( a.goalsScored > b.goalsScored ) {
return true;
} else if ( a.goalsScored < b.goalsScored ){
return false;
}
if ( a.gamesPlayed < b.gamesPlayed ) {
return true;
} else if ( a.gamesPlayed > b.gamesPlayed ) {
return false;
}
return strcasecmp(a.name, b.name) < 0;
}
int main() {
char line[MAXLINE];
cin.getline(line, MAXLINE);
int nOfTournment = atoi(line);
for (int t = 0; t < nOfTournment; t++) {
if ( t != 0 ) {
cout << endl;
}
// Reads the tournment name
cin.getline(line, MAXLINE);
int lengthTournmentName = strlen(line);
char tournamentName[lengthTournmentName + 1];
strcpy(tournamentName, line);
// How many teams?
cin.getline(line, MAXLINE);
int nOfTeams = atoi(line);
Team teams[nOfTeams];
for ( int team = 0; team < nOfTeams; team++) {
// Reads the name of the team
cin.getline(line, MAXLINE);
initializeTeam(teams[team], line);
}
// How many games?
cin.getline(line, MAXLINE);
int nOfGames = atoi(line);
for ( int game = 0; game < nOfGames; game++ ) {
// Reads the game
cin.getline(line, MAXLINE);
parseGame(line, teams);
}
// Sorts
sort(teams, teams + nOfTeams, compareTeams);
// Prints
cout << tournamentName << endl;
for ( int team = 0; team < nOfTeams; team ++ ) {
Team tm = teams[team];
printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", team+1, tm.name,
tm.points, tm.gamesPlayed, tm.wins,
(tm.gamesPlayed-tm.wins-tm.losses), tm.losses,
(tm.goalsScored - tm.goalsAgainst), tm.goalsScored,
tm.goalsAgainst);
}
}
return 0;
}
Re: 10194 - Football (aka Soccer)
![:evil:](./images/smilies/icon_evil.gif)
![:evil:](./images/smilies/icon_evil.gif)
![:evil:](./images/smilies/icon_evil.gif)
I finally solved this problem with Java.
There is the same issue similar to problem 10197 - Learning Portuguese.
!!! The default system encoding is different from the judge data files. !!!
For the detail, please reference this thread:
http://acm.uva.es/board/viewtopic.php?f ... 30#p140856
OK
![:wink:](./images/smilies/icon_wink.gif)
Code: Select all
Scanner cin = new Scanner(System.in, "ISO-8859-1");
PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out, "ISO-8859-1"));
// your code here
cout.flush();
-
- New poster
- Posts: 10
- Joined: Wed Dec 15, 2010 12:32 pm
Re: 10194 - Football (aka Soccer)
I got ACed by converting every lower case letter into upper case letter in my own string comparing function.
Re: 10194 - Football (aka Soccer)
Just got AC on this problem.
For the C++ users:
The following should be the last line of your boolean comparator
strcasecmp is somehow not well documented function but the judge accepted my solution along with it
For the C++ users:
The following should be the last line of your boolean comparator
Code: Select all
return strcasecmp(team1Name, team2Name) < 0;
-
- Experienced poster
- Posts: 122
- Joined: Tue Apr 16, 2002 10:07 am
Re: 10194 - Football (aka Soccer)
Hi guys,
I just got this problem AC using C++ and wanted to share the way I am taking the input.
Instead of writing extra code for doing the parsing job, let C or C++ do it for you.
Using the above way, the data is automatically parsed and stored in their respective variables.
A quick explanation after decomposition:
I also used the qsort function from <stdlib.h>.
Happy coding and happy new year 2012!![:wink:](./images/smilies/icon_wink.gif)
I just got this problem AC using C++ and wanted to share the way I am taking the input.
Instead of writing extra code for doing the parsing job, let C or C++ do it for you.
Code: Select all
char team1[31], team2[31];
int goalsForTeam1, goalsForTeam2;
.
.
scanf ("%[^#]#%d@%d#%[^\n]\n", team1, &goalsForTeam1, &goalsForTeam2, team2);
A quick explanation after decomposition:
Code: Select all
%[^#] - this will take all the characters until the # character is encountered. The string will be stored in the variable 'team1'.
# - when this character is encountered, the scanf function will consume it. It is not stored in the variables.
%d@ - will take a normal integer value until the character @ is encountered. The integer is stored in the variable 'goalsForTeam1'.
%d# - will take a normal integer value until the character # is encountered. The integer is stored in the variable 'goalsForTeam2'.
[^\n] - will take any character till end of line is encountered. The string will be stored in the variable 'team2'.
\n - when this character is encountered, the scanf function will consume it and hence will not be sent to the next string to be read.
Using this technique, we avoid flushing stdin.
Happy coding and happy new year 2012!
![:wink:](./images/smilies/icon_wink.gif)
-
- New poster
- Posts: 11
- Joined: Mon Feb 20, 2012 11:04 am
Re: 10194 - Football (aka Soccer)
Code: Select all
Accepted after so many wrong answer..
thank you very much amishera for your test data.
plz help me..
Re: 10194 - Football (aka Soccer)
Accepted![]()
. Compare Function's string compare insensitive.
-
- Learning poster
- Posts: 87
- Joined: Thu Dec 15, 2011 3:08 pm
- Location: University of Rajshahi,Bangladesh
Re: 10194 - Football (aka Soccer)
it was only a silly mistake ..........
thanks brianfry713![:)](./images/smilies/icon_smile.gif)
thanks brianfry713
![:)](./images/smilies/icon_smile.gif)
Last edited by mahade hasan on Fri Mar 08, 2013 5:57 am, edited 1 time in total.
we r surrounded by happiness
need eyes to feel it!
need eyes to feel it!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re:
animenologist wrote:Here's the input and output I used. I used it to test whether or not the comparisons were working correctly, by creating two teams that would make it all the way to that level. Also, my last case, I had them with different cases to make sure that they were sorted by lexicographical order.
Input:Output:Code: Select all
6 Test 1 4 A B C D 3 A#3@1#C A#1@1#C B#3@0#D TEST 2 4 A B C D 5 A#3@1#C B#1@1#D B#1@1#D B#1@1#D B#0@1#D TEST 3 4 A B C D 2 A#2@1#C B#3@1#D TEST 4 4 A B C D 3 A#3@1#C B#4@1#D B#1@2#D TEST 5 4 A B C D 3 B#3@1#C A#3@0#D A#0@1#D TEST 6 5 aa BB c D eE 0 Test 6 4 A B C D 3 A#1@3#C A#1@1#C B#0@3#D
Code: Select all
Test 1 1) A 4p, 2g (1-1-0), 2gd (4-2) 2) B 3p, 1g (1-0-0), 3gd (3-0) 3) C 1p, 2g (0-1-1), -2gd (2-4) 4) D 0p, 1g (0-0-1), -3gd (0-3) TEST 2 1) D 6p, 4g (1-3-0), 1gd (4-3) 2) A 3p, 1g (1-0-0), 2gd (3-1) 3) B 3p, 4g (0-3-1), -1gd (3-4) 4) C 0p, 1g (0-0-1), -2gd (1-3) TEST 3 1) B 3p, 1g (1-0-0), 2gd (3-1) 2) A 3p, 1g (1-0-0), 1gd (2-1) 3) C 0p, 1g (0-0-1), -1gd (1-2) 4) D 0p, 1g (0-0-1), -2gd (1-3) TEST 4 1) B 3p, 2g (1-0-1), 2gd (5-3) 2) A 3p, 1g (1-0-0), 2gd (3-1) 3) D 3p, 2g (1-0-1), -2gd (3-5) 4) C 0p, 1g (0-0-1), -2gd (1-3) TEST 5 1) B 3p, 1g (1-0-0), 2gd (3-1) 2) A 3p, 2g (1-0-1), 2gd (3-1) 3) D 3p, 2g (1-0-1), -2gd (1-3) 4) C 0p, 1g (0-0-1), -2gd (1-3) TEST 6 1) aa 0p, 0g (0-0-0), 0gd (0-0) 2) BB 0p, 0g (0-0-0), 0gd (0-0) 3) c 0p, 0g (0-0-0), 0gd (0-0) 4) D 0p, 0g (0-0-0), 0gd (0-0) 5) eE 0p, 0g (0-0-0), 0gd (0-0)
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 5
- Joined: Sat Apr 06, 2013 12:42 pm
- Location: Dhaka, Bangladesh
- Contact:
Re: 10194 - Football (aka Soccer)
What is wrong here?
Code: Select all
// Program :
// Author : Anindya Sundar Paul
// Run-time:
// Verdict : WA
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
using namespace std;
#define EPS 1e-9
#define INF 2147483647
#define PI 3.14159265358979323846264338327950
#define MEM( x, y ) memset( x, y, sizeof( x ) )
#define READ( file ) freopen( file, "r", stdin )
#define WRITE( file ) freopen( file, "w", stdout )
typedef long long LL;
typedef unsigned long long ULL;
/// Template ends, coding starts
class Team {
public:
string name;
int points;
int played;
int wins;
int ties;
int losses;
int gd, gs, ga;
Team() { points = 0; played = 0; wins = 0; ties = 0; losses = 0; gd = 0; ga = 0; gs = 0; }
bool operator < ( const Team& x ) const
{
if( points != x.points ) return points > x.points;
if( wins != x.wins ) return wins > x.wins;
if( gd != x.gd ) return gd > x.gd;
if( gs != x.gs ) return gs > x.gs;
if( played != x.played ) return played < x.played;
char str1[100], str2[100];
strcpy( str1, name.c_str() );
strcpy( str2, x.name.c_str() );
for( int i = 0; str1[i]; i++ ) str1[i] = tolower( str1[i] );
for( int i = 0; str2[i]; i++ ) str2[i] = tolower( str2[i] );
return strcmp( str1, str2 ) < 0;
}
};
vector <Team> v;
int main()
{
// freopen( "in.txt", "r", stdin );
// freopen( "out.txt", "w", stdout );
int n, i;
cin >> n;
getchar();
while( n-- ) {
char str[110];
char tourName[110];
gets( tourName );
int nTeams;
cin >> nTeams;
getchar();
v.clear();
for( i = 0; i < nTeams; i++ ) {
gets( str );
string s( str );
Team t;
t.name = s;
v.push_back( t );
}
int m, j;
cin >> m;
getchar();
while( m-- ) {
gets( str );
char t1[100], t2[100], g1[10], g2[10];
bool hashFlag = false;
for( i = 0; str[i] != '@'; i++ ) {
if( !hashFlag && str[i] == '#' ) {
strncpy( t1, str, i );
t1[i] = 0;
hashFlag = true;
j = 0;
}
else {
g1[j] = str[i];
g1[j+1] = 0;
j++;
}
}
i++;
j = 0;
hashFlag = false;
for( ; str[i]; i++ ) {
if( !hashFlag && str[i] != '#' ) {
g2[j] = str[i];
g2[j+1] = 0;
j++;
}
else break;
}
strcpy( t2, &str[i+1] );
int goal1 = atoi( g1 );
int goal2 = atoi( g2 );
for( i = 0; i < nTeams; i++ ) {
if( !( v[i].name.compare( t1 ) ) ) {
v[i].played++;
v[i].gs += goal1;
v[i].ga += goal2;
v[i].gd = v[i].gs - v[i].ga;
if( goal1 > goal2 ) {
v[i].wins++;
v[i].points += 3;
}
else if( goal1 == goal2 ) {
v[i].ties++;
v[i].points++;
}
else v[i].losses++;
}
else if( !( v[i].name.compare( t2 ) ) ) {
v[i].played++;
v[i].gs += goal2;
v[i].ga += goal1;
v[i].gd = v[i].gs - v[i].ga;
if( goal2 > goal1 ) {
v[i].wins++;
v[i].points += 3;
}
else if( goal1 == goal2 ) {
v[i].ties++;
v[i].points++;
}
else v[i].losses++;
}
}
}
sort( v.begin(), v.end() );
puts( tourName );
for( i = 0; i < nTeams; i++ ) {
printf( "%d) ", i+1 );
cout << v[i].name << ' ' << v[i].points << 'p' << ", " << v[i].played << 'g';
printf( " (%d-%d-%d), %dgd (%d-%d)\n", v[i].wins, v[i].ties, v[i].losses, v[i].gd, v[i].gs, v[i].ga );
}
if( n != 0 ) puts( "" );
}
return 0;
}
Website: http://binaryrongo.wordpress.com
Facebook: http://facebook.com/aspaul.93
Twitter: http://twitter.com/anindyaspaul
LinkedIn: http://bd.linkedin.com/in/aspaul
UVa: http://uhunt.felix-halim.net/id/210560
Facebook: http://facebook.com/aspaul.93
Twitter: http://twitter.com/anindyaspaul
LinkedIn: http://bd.linkedin.com/in/aspaul
UVa: http://uhunt.felix-halim.net/id/210560
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10194 - Football (aka Soccer)
On my machine your code is throwing a seg fault on line 118:
g1[j] = str;
j is uninitialized.
g1[j] = str;
j is uninitialized.
Check input and AC output for thousands of problems on uDebug!
Re: 10194 - Football (aka Soccer)
Hi all
i got WA but my code gave me correct answers
can anyone test it with special cases that may i ignore please
/*Code removed after AC*/
i got WA but my code gave me correct answers
can anyone test it with special cases that may i ignore please
/*Code removed after AC*/
Last edited by Sam Nemo on Fri Feb 21, 2014 11:58 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10194 - Football (aka Soccer)
Don't read and write to files.
Check input and AC output for thousands of problems on uDebug!
Re: 10194 - Football (aka Soccer)
thanks for your reply but i usually remove read/write to files lines before sending it to the sitebrianfry713 wrote:Don't read and write to files.
but finallyy the wrong answer came when I select whitch teams is playing the games in the function t6ab8()
and finally get AC