## 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

chelosalas
New poster
Posts: 1
Joined: Mon Apr 13, 2009 1:20 am

### 10194 Aka Soccer question

Hello...

I'm trying to solve 10194-aka Soccer with a Java program, I tested various cases but always received WA answer from judge, I read another post witch says that nobody solve aka Soccer using Java. It's that right? (so they move to C++ for the solution).
Another people say: use case insensitive comparison for lexicographic in Sort, I tried toUpperCase, toLowerCase, compareToIgnoreCase but still WA answer.
Searching for a test case I found the following:
INPUT
1
Tour name
2
Brazil
Norway
1
brAzil#2@1#NoRwAy

My program give the following result:
Tour name
1) Brazil 3p, 1g (1-0-0), 1gd (2-1)
2) Norway 0p, 1g (0-0-1), -1gd (1-2)

But using UVA toolkit Problem Database and Solver (http://www.uvatoolkit.com/problemssolve.php) have the following result:
Tour name
1) Norway 0p, 0g (0-0-0), 0gd (0-0)
2) Brazil 0p, 1g (0-0-1), -1gd (1-2)

I think that my program gives the correct result (because using case insensitive comparison Brazil its equal to brAzil in games played for a team...).
Thinking something unimaginable. I have the following question: that the judge have the correct results for this problem? or am I wrong?

If you want to look my program, I attached it at the end of this post.

Regards
Marcelo Salas

Code: Select all

``````import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Arrays;
import java.io.BufferedInputStream;

/**
*
* @author Lic. Marcelo Salas Vargas
*         Problema: 10194 aka Soccer
*/
class Equipo implements Comparable<Equipo> {

String nombre;
int puntos_totales;
int partidos_perdidos;
int gol_diferencia;
int gol_a_favor;
int gol_en_contra;

public Equipo(String nombre) {
this.nombre=nombre;
this.puntos_totales=0;
this.partidos_perdidos=0;
this.gol_diferencia=0;
this.gol_a_favor=0;
this.gol_en_contra=0;
}

public void SetScore(int gol_equipo,int gol_contrario) {
this.gol_a_favor=this.gol_a_favor+gol_equipo;
this.gol_en_contra=this.gol_en_contra+gol_contrario;
this.gol_diferencia=this.gol_a_favor - this.gol_en_contra;
else if(gol_equipo<gol_contrario) this.partidos_perdidos++;
}

public String GetNombre(){
return this.nombre;
}

public int GetPuntosTotales(){
return this.puntos_totales;
}

}

}

}

public int GetPartidosPerdidos(){
return this.partidos_perdidos;
}

public int GetGolDiferencia(){
return this.gol_diferencia;
}

public int GetGolAFavor(){
return this.gol_a_favor;
}

public int GetGolEnContra(){
return this.gol_en_contra;
}

public int compareTo(Equipo other) {
//Criterio 1.- Mayores puntos logrados
if (this.puntos_totales>other.puntos_totales) return(-1);
if (this.puntos_totales<other.puntos_totales) return(1);
//Criterio 2.- Mayores victorias
//Criterio 3.- Gol diferencia
if (this.gol_diferencia>other.gol_diferencia) return(-1);
if (this.gol_diferencia<other.gol_diferencia) return(1);
//Criterio 4.- Mayores goles anotados
if (this.gol_a_favor>other.gol_a_favor) return(-1);
if (this.gol_a_favor<other.gol_a_favor) return(1);
//Criterio 5.- Menores juegos jugados
//Criterio 6.- Orden Lexicografico
return (this.nombre.compareToIgnoreCase(other.nombre));
}

public String toString() {
return(this.nombre+" "+Integer.toString(this.puntos_totales)+"p, "+Integer.toString(this.partidos_jugados)+"g "+
Integer.toString(this.gol_diferencia)+"gd "+
"("+Integer.toString(this.gol_a_favor)+"-"+Integer.toString(this.gol_en_contra)+")");
}

}

public class Main {

private void parseLine(String line,Equipo[] equipos,int n) {
String line1=new String();
String line2=new String();
String team1=new String();
String team2=new String();
int goles1=0;
int goles2=0;

try {
Scanner lineScanner = new Scanner(line);
lineScanner.useDelimiter("\\s*@\\s*");
if (lineScanner.hasNext()) line1=lineScanner.next();
if (lineScanner.hasNext()) line2=lineScanner.next();

Scanner equipoScanner1 = new Scanner(line1);
equipoScanner1.useDelimiter("\\s*#\\s*");
if (equipoScanner1.hasNext()) team1=equipoScanner1.next();
if (equipoScanner1.hasNext()) goles1=equipoScanner1.nextInt(); //Integer.parseInt(lineScanner.next());

Scanner equipoScanner2 = new Scanner(line2);
equipoScanner2.useDelimiter("\\s*#\\s*");
if (equipoScanner2.hasNext()) goles2=equipoScanner2.nextInt(); //Integer.parseInt(lineScanner.next());
if (equipoScanner2.hasNext()) team2=equipoScanner2.next();

if(!team1.equalsIgnoreCase(team2)) {
//Colocar Score del partido para team1
for(int i=0;i<n;i++)
if(team1.equalsIgnoreCase(equipos[i].GetNombre())) equipos[i].SetScore(goles1,goles2);
//Colocar Score del partido para team2
for(int i=0;i<n;i++)
if(team2.equalsIgnoreCase(equipos[i].GetNombre())) equipos[i].SetScore(goles2,goles1);
}

} catch (Exception e) {
e.printStackTrace();
}

}

private void leerTorneo() {
int ntorneos=0;
int ctorneos=0;
int nequipos=0;
int cequipos=0;
int npartidos=0;
int cpartidos=0;
try {
Scanner scanner = new Scanner(new BufferedInputStream(System.in));

scanner.useDelimiter(System.getProperty("line.separator"));

Equipo[] equipos = new Equipo[255];

if (scanner.hasNext()) ntorneos = Integer.parseInt(scanner.nextLine());
if(ntorneos>0) {
ctorneos = 0;
while (scanner.hasNext() && ctorneos < ntorneos) {
//Lee nombre del Torneo
if (ctorneos>0) System.out.println();
System.out.println(scanner.nextLine());

//Leer numero de equipos del torneo
if (scanner.hasNext()) nequipos = Integer.parseInt(scanner.nextLine());

if(nequipos>1 && nequipos<=30) {
//Leer equipos del torneo
cequipos = 0;
while (scanner.hasNext() && cequipos < nequipos) {
//Lee nombre del equipo y almacenarlo
equipos[cequipos]=new Equipo(scanner.nextLine());
//Siguiente Equipo
cequipos++;
}

}

//Leer numero de partidos del torneo
if (scanner.hasNext()) npartidos = Integer.parseInt(scanner.nextLine());

if(npartidos>0 && npartidos<=1000) {
//Leer partidos del torneo
cpartidos = 0;
while (scanner.hasNext() && cpartidos < npartidos) {
//Lee Score del Partido
String linea=scanner.nextLine();
//Parsear la linea del Score
parseLine(linea,equipos,nequipos);
//Siguiente Partido
cpartidos++;
}

}

//Una vez cargados los Scores Sortear la Lista de Equipos
if (cequipos>0 && cpartidos>0) {
Arrays.sort(equipos,0,cequipos);
for(int i=0;i<cequipos;i++) {
System.out.println(Integer.toString(i+1)+") "+equipos[i]);
}
}

//Siguiente Torneo
ctorneos++;
}
}

scanner.close();
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
//if (args.length != 1) {
//    System.err.println("Usage: java SoccerProblem " + "input file");
//    System.exit(0);
//}
Main soc=new Main();
soc.leerTorneo();
System.exit(0);
}
}
``````

mohitkanwal
New poster
Posts: 7
Joined: Sun Mar 29, 2009 6:32 pm

### Re: 10194 - Football (aka Soccer)

Hello guys, i have every post in the section n still can't get my program to work kepping on getting WAs for my code.I also tried the code at programming challenges still WA... it's a bit long ..i checked the program at http://www.youngprogrammer.com but could not use it to find the error in my code ... and besides wat does
(char*) str is used to give in return ??

Code: Select all

``````#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <cctype>
#include <map>
using namespace std;
#include <conio.h>

#define MAXT 31
#define MAX 1000
#define WIN 1
#define TIE 0
#define LOSS 2

struct team{
char team_name[31];
unsigned int b;//points
unsigned int c;//games played
unsigned int d;//wins
unsigned int e;//ties
unsigned int f;//losses
int g;//h-i
int h;//scored goals
int i;//against goals
};

int StrCmp(char temp[], char dummy[]) {
int i, l;
l = min(strlen(temp),strlen(dummy));
for(i = 0; i<l; i++) {
if(tolower(temp[i]) > tolower(dummy[i])) return 1;
else if(tolower(temp[i]) < tolower(dummy[i])) return -1;
}
if(strlen(temp)>strlen(dummy)) return 1;
else if(strlen(temp)<strlen(dummy)) return -1;
return 0;
}
bool str_insensitive(char* str1,char* str2)
{
char s1[256],s2[256];
int l1 = strlen(str1);int l2 = strlen (str2);
for(int i = 0; i< l1; i++)
{
if(isalpha(str1[i])) s1[i] = tolower(str1[i]);
else
s1[i] = str1[i];
}
for(int i = 0; i< l2; i++)
{
if(isalpha(str2[i])) s2[i] = tolower(str2[i]);
else
s2[i] = str2[i];
}
//comparing now
if(strcmp(s1,s2) == 1) return true;
else             return false;
}
char* toLower(char *str)
{
char ans[256];
int l = strlen(str);
for(int i=0;i<l;i++)
ans[i] = tolower(str[i]);
return ans;
}

bool comp(team &t1 , team &t2)
{
if(t1.b==t2.b)
{
if(t1.d == t2.d)
{
if(t1.g == t2.g)
{
if(t1.h==t2.h)
{
if(t1.c==t2.c)
{
if(StrCmp(t1.team_name,t2.team_name) == 1)
return true;

else
return false;
//str_insensitive(t1.team_name,t2.team_name);
}
else if(t1.c<t2.c)
return false;
else
return true;
}
else if(t1.h>t2.h)
return false;
else
return true;
}
else if(t1.g>t2.g)
return false;
else
return true;
}
else if(t1.d>t2.d)
return false;
else
return true;
}
else if(t1.b>t2.b)
return false;
else
return true;
}

bool swap(team &t1,team &t2)
{
team temp;
temp = t1;
t1 = t2;
t2 = temp;
return true;
}

void bubblesort(team s[],int size)
{
bool swapped;
do{
swapped = false;
for(int i=0;i<size-1;i++)
{
if(comp(s[i],s[i+1]))
{
swap(s[i],s[i+1]);
swapped = true;
}
}
}while(swapped);
}

void doing()
{
char tournament[256];
cin.getline(tournament,255);
map <string,int> pos;//hash table
team T[MAXT];char buffer[256];
int teams;
int games;
cin.getline(buffer,255,'\n');
teams = atoi(buffer);
//scanf("%d",&teams);
//cin.ignore(255,'\n');
//cout<<"here"<<endl;
for(int i=0;i<teams;i++)
{
char temp[80];
cin.getline(temp,30);
//scanf("%s",&temp);
pos[temp] = i;
// T[i].team_name = temp;
strcpy(T[i].team_name,temp);
// cout<<T[i].team_name;
T[i].b=0;T[i].c=0;T[i].d=0;T[i].e=0;T[i].f=0;T[i].g=0;T[i].h=0;T[i].i=0;
}
// cin.ignore(255,'\n');
//need to get match info
cin.getline(buffer,255,'\n');
games = atoi(buffer);
//cin>>games;
//scanf("%d",&games);
//cin.ignore(255,'\n');
for(int i=0;i<games;i++)
{

char team1[31],team2[31];
int goal1,goal2;
cin.getline(team1,30,'#');
scanf("%d@%d#",&goal1,&goal2);
cin.getline(team2,30);
//scanf("%s#%d@%d#%s\n", team1,&goal1,&goal2,team2);
// cout<<team1<<" "<<team2 <<" "<< goal1<<" "<<goal2<<endl;
if(goal1>goal2)
{
//cout<<team1 <<"wins"<< goal1<<goal2<<endl;
T[pos[team1]].b+=3;
T[pos[team1]].d++;T[pos[team2]].f++;
}
else if(goal2>goal1)
{
//cout<<team2<<"wins"<<goal1<<goal2<<endl;
T[pos[team2]].b+=3;
T[pos[team2]].d++;T[pos[team1]].f++;
}
else
{
T[pos[team1]].b+=1; T[pos[team2]].b+=1;
T[pos[team1]].e++;T[pos[team2]].e++;
}
//cout<<T[pos[team1]].team_name<<" "<<T[pos[team2]].team_name <<" "<< goal1<<" "<<goal2<<endl;
//update games played
T[pos[team1]].c+=1;T[pos[team2]].c+=1;
//goals
T[pos[team1]].i+=goal2;
T[pos[team2]].i+=goal1;
//  cout<<T[pos[team1]].h<<endl;
T[pos[team1]].h+=goal1;T[pos[team2]].h+=goal2;
// cout<<T[pos[team1]].h<<" "<<T[pos[team2]].h<<endl;
T[pos[team1]].g = T[pos[team1]].h - T[pos[team1]].i;
T[pos[team2]].g = T[pos[team2]].h - T[pos[team2]].i;
}
bubblesort(T,teams);
printf("%s\n",tournament);
for(int i=0;i<teams;i++)
printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",(i+1),T[i].team_name,T[i].b,
T[i].c, T[i].d,T[i].e,T[i].f,T[i].g,
T[i].h,T[i].i);
//getch();

}
int main()
{
char buffer[256];
cin.getline(buffer,255);
int cases;
cases = atoi(buffer);
for(int i=0;i<cases;i++)
{
doing();
if(i!=cases-1) cout<<endl;
}
getch();
return 0;
}
``````
Thanks

helenxy
New poster
Posts: 1
Joined: Fri Jul 03, 2009 8:23 am

### Re: 10194 Aka Soccer question

How do you strike a soccer ball for a penalty kick? I am a great soccer player but when I step on the line to take a penalty kick I always miss the friggin net!!! Can you please help me and tell me how to strike the soccer ball better?

New poster
Posts: 1
Joined: Tue Sep 15, 2009 6:43 am

### 10194

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
char *lwr(char *string)
{
char *real_string;
real_string=string;
while(*string){
*string=tolower(*string);
string++;
}
return(real_string);
}
struct node{
char name[30];
int pt;
int gm;
int win;
int tie;
int loss;
int diff;
int score;
int against;
};
char T[100];
int cf(const void *a,const void *b)
{
char u[30],q[30];
struct node *x=(struct node *) a;
struct node *y=(struct node *) b;
if(y->pt!=x->pt)
return y->pt-x->pt;
else if(y->win!=x->win)
return y->win-x->win;
else if(y->diff!=x->diff)
return y->diff-x->diff;
else if(y->score!=x->score)
return y->score-x->score;
else if(x->gm!=y->gm)
return x->gm-y->gm;
else{
strcpy(u,x->name);
strcpy(q,y->name);
return (strcmp(lwr(u),lwr(q)));
}
}
int main(void)
{
int n,t,g1,g2,p1,p2,i,j,k,p,c;
char t1[30],t2[30];
scanf(" %d",&n);
for(i=0;i<n;++i){
scanf(" %[^\n]",T);
scanf(" %d",&t);
struct node team[30]={"",0,0,0,0,0,0,0,0};
for(j=0;j<t;++j)
scanf(" %[^\n]",team[j].name);
scanf(" %d",&p);
for(j=0;j<p;++j){
scanf(" %[^#]",t1);
scanf("#%d@%d",&g1,&g2);
scanf("#%[^\n]",t2);
p1=g1>g2?3:g1==g2?1:0;
p2=g2>g1?3:g1==g2?1:0;
k=0;
for(c=0;c<t;++c){
if(strcmp(team[c].name,t1)==0){
team[c].pt+=p1;
++team[c].gm;
p1==3?++team[c].win:p1==1?++team[c].tie:++team[c].loss;
team[c].diff+=g1-g2;
team[c].score+=g1;
team[c].against+=g2;
++k;
}
else if(strcmp(team[c].name,t2)==0){
team[c].pt+=p2;
++team[c].gm;
p2==3?++team[c].win:p2==1?++team[c].tie:++team[c].loss;
team[c].diff+=g2-g1;
team[c].score+=g2;
team[c].against+=g1;
++k;
}
else if(k==2)
break;
}
}
qsort(team,t,sizeof(node),cf);
puts(T);
for(j=0;j<t;++j)
printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",j+1,team[j].name,team[j].pt,team[j].gm,team[j].win,team[j].tie,team[j].loss,team[j].diff,team[j].score,team[j].against);
putchar('\n');
}
return 0;
}

I am getting wa. help me

Bruno
New poster
Posts: 22
Joined: Thu Oct 01, 2009 9:03 pm

### 10194 - Problem A: Football (aka Soccer)

Link to problem: http://uva.onlinejudge.org/index.php?op ... oblem=1135
UID: 10194

Hello! Have you ever thought that your program is right and when you send to UVa you get a big Wrong Answer? And then you try to find a error on your code, go to UVa toolkit and test billions of cases but your program is giving all the correct results? Its happening to me
I am beginning at this programming contests world and I need to learn many things, I am using C++. This is a basic program I know, but I cant get it to work!

Anyone could please check out my code? My code is attached!
Is there any tips for me? Something I am making wrong, or I could do better, any tips for performance, code style? Anything would be appreciated

Thank you!
Bruno
Attachments
Football.cpp.zip
Source code :)
Last edited by Bruno on Fri Oct 02, 2009 9:03 pm, edited 1 time in total.

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

### Re: Problem A: Football (aka Soccer)

We usually follow some rules before making a post and some of those are

1] Search the board for existing threads for the problem under consideration
2] If a thread already exists, make your post in that one.
3] The subject should be of the format "problem number - problem name"

Coming back to your problem, there should be one new line between consecutive output sets and not after ever set. I am not sure whether this is the only reason for getting WA, though!

Bruno
New poster
Posts: 22
Joined: Thu Oct 01, 2009 9:03 pm

### Re: 10194 - Problem A: Football (aka Soccer)

Sorry :p

No, it is not the reason for WA

Bruno
New poster
Posts: 22
Joined: Thu Oct 01, 2009 9:03 pm

### Re: 10194 - Problem A: Football (aka Soccer)

I changed strcmp to strcasecmp and it is working now

Thank you!

aprogrammer
New poster
Posts: 1
Joined: Wed Oct 14, 2009 6:42 pm

### Re: 10194 - Football (aka Soccer)

Please, someone, could help me?

I have tried all possibilities (and suggestions in this forum), but I always receive WA.
Maybe something different in Java?

Here is my code:

Code: Select all

``````import java.io.File;
import java.io.FileInputStream;
import java.util.Collections;
import java.util.Vector;
import java.util.Scanner;

class Main {

public static void main(String[] args) throws Exception {
//System.setIn(new FileInputStream(new File("110408.inp")));
Scanner scanner = new Scanner(System.in);

if (scanner.hasNext()) {
int nTournament = scanner.nextInt();
scanner.nextLine();
for (int i = 0; i < nTournament; i++) {
Vector<Time> times = new Vector<Time>();
String tournamentName = scanner.nextLine();
int nTeams = scanner.nextInt();
scanner.nextLine();
for (int j = 0; j < nTeams; j++) {
String timeName = scanner.nextLine();
Time t = new Time(timeName);
}
int nGames = scanner.nextInt();
scanner.nextLine();
for (int j = 0; j < nGames; j++) {
String gameResult = scanner.nextLine();
handleGame(times, gameResult);
}
Collections.sort(times);
System.out.println(tournamentName);
for (int j = 0; j < times.size(); j++) {
System.out.print((j + 1) + ") ");
System.out.println(times.get(j));
}
if (i < (nTournament - 1))
System.out.println("");

}
}

} // do main

static void handleGame(Vector<Time> times, String gameResult) {
String partsOfGame[] = gameResult.split("#");
String goals[] = partsOfGame[1].split("@");
Time t1 = times.get(times.indexOf(new Time(partsOfGame[0])));
Time t2 = times.get(times.indexOf(new Time(partsOfGame[2])));
int t1Goals = Integer.parseInt(goals[0]);
int t2Goals = Integer.parseInt(goals[1]);
t1.nGoals += t1Goals;
t2.nGoals += t2Goals;
t1.nGames++;
t2.nGames++;
t1.nGoalsAgainst += t2Goals;
t2.nGoalsAgainst += t1Goals;
if (t1Goals == t2Goals) {
t1.nTiesGames++;
t2.nTiesGames++;
t1.points++;
t2.points++;
} else if (t1Goals > t2Goals) {
t1.nWinnedGames++;
t2.nLostGames++;
t1.points += 3;
} else {
t2.nWinnedGames++;
t1.nLostGames++;
t2.points += 3;
}
t1.goalsDiff += t1Goals - t2Goals;
t2.goalsDiff += t2Goals - t1Goals;
}

}

class Time implements Comparable<Time> {
String name;

int nGoals = 0;

int nGames = 0;

int nWinnedGames = 0;

int nLostGames = 0;

int nTiesGames = 0;

int nGoalsAgainst = 0;

int points = 0;

int goalsDiff = 0;

Time(String timeName) {
name = timeName;
}

public int compareTo(Time o) {

int comp = o.points - points;
if (comp != 0)
return comp;
comp = o.nWinnedGames - nWinnedGames;
if (comp != 0)
return comp;
comp = o.goalsDiff - goalsDiff;
if (comp != 0)
return comp;
comp = o.nGoals - nGoals;
if (comp != 0)
return comp;
comp = nGames - o.nGames;
if (comp != 0)
return comp;
comp = name.compareToIgnoreCase(o.name);
return comp;
}

public boolean equals(Object o) {
if (o instanceof Time){
Time par = (Time)o;
//if (par.name.compareToIgnoreCase(name)==0) return true;
if (par.name.compareTo(name)==0) return true;
}
return false;
}

public String toString() {
return name + " " + points + "p, " + nGames + "g (" + nWinnedGames
+ "-" + nTiesGames + "-" + nLostGames + "), " + "" + goalsDiff
+ "gd (" + nGoals + "-" + nGoalsAgainst + ")";
}

}
``````
Thanks a lot!

amishera
New poster
Posts: 38
Joined: Sat Dec 27, 2008 10:42 pm

### Re: 10194 - Football (aka Soccer)

Some test data for my accepted code:

Input:
18
World Cup 1998 - Group A
4
Brazil
Norway
Morocco
Scotland
6
Brazil#2@1#Scotland
Norway#2@2#Morocco
Scotland#1@1#Norway
Brazil#3@0#Morocco
Morocco#3@0#Scotland
Brazil#1@2#Norway
Some strange tournament
5
Team A
Team B
Team C
Team D
Team E
5
Team A#1@1#Team B
Team A#2@2#Team C
Team A#0@0#Team D
Team E#2@1#Team C
Team E#1@2#Team D
Penultimate Tournament
5
A
B
C
D
E
5
A#2@0#B
A#1@0#C
B#3@0#D
C#3@0#D
C#0@1#E
Last Tournament
3
Gato
Lobo
Mono
3
Gato#2@2#Lobo
Lobo#1@1#Mono
Mono#3@3#Gato
2010 FIFA World Cup qualification (CAF) 2nd round Group 5
4
Gabon
Ghana
Lesotho
Libya
12
Ghana#3@0#Libya
Libya#1@0#Gabon
Lesotho#2@3#Ghana
Gabon#2@0#Ghana
Lesotho#0@1#Libya
Libya#4@0#Lesotho
Ghana#2@0#Gabon
Gabon#2@0#Lesotho
Libya#1@0#Ghana
Lesotho#0@3#Gabon
Gabon#1@0#Libya
Ghana#3@0#Lesotho
2010 FIFA World Cup qualification (CAF)
6
Comoros
Somalia
Sierra Leone
Guinea-Bissau
Djibouti
5
Djibouti#1@0#Somalia
Sierra Leone#1@0#Guinea-Bissau
Sierra Leone#0@0#Guinea-Bissau
2010 FIFA World Cup qualification (CAF) 2nd round Group 1
4
Cameroon
CapeVerde
Mauritius
Tanzania
12
Tanzania#1@1#Mauritius
Cameroon#2@0#CapeVerde
CapeVerde#1@0#Tanzania
Mauritius#0@3#Cameroon
Tanzania#0@0#Cameroon
Mauritius#0@1#CapeVerde
Cameroon#2@1#Tanzania
CapeVerde#3@1#Mauritius
Mauritius#1@4#Tanzania
CapeVerde#1@2#Cameroon
Tanzania#3@1#CapeVerde
Cameroon#5@0#Mauritius
2010 FIFA World Cup qualification (CAF) 2nd round Group 2
4
Guinea
Kenya
Namibia
Zimbabwe
12
Namibia#2@1#Kenya
Guinea#0@0#Zimbabwe
Kenya#2@0#Guinea
Zimbabwe#2@0#Namibia
Kenya#2@0#Zimbabwe
Namibia#1@2#Guinea
Zimbabwe#0@0#Kenya
Guinea#4@0#Namibia
Kenya#1@0#Namibia
Zimbabwe#0@0#Guinea
Namibia#4@2#Zimbabwe
Guinea#3@2#Kenya
2010 FIFA World Cup qualification (CAF) 2nd round Group 3
4
Angola
Benin
Niger
Uganda
12
Uganda#1@0#Niger
Angola#3@0#Benin
Benin#4@1#Uganda
Niger#1@2#Angola
Uganda#3@1#Angola
Niger#0@2#Benin
Benin#2@0#Niger
Angola#0@0#Uganda
Benin#3@2#Angola
Niger#3@1#Uganda
Uganda#2@1#Benin
Angola#3@1#Niger
2010 FIFA World Cup qualification (CAF) 2nd round Group 4
4
EquatorialGuinea
Nigeria
SierraLeone
SouthAfrica
12
EquatorialGuinea#2@0#SierraLeone
Nigeria#2@0#SouthAfrica
SouthAfrica#4@1#EquatorialGuinea
SierraLeone#0@1#Nigeria
SierraLeone#1@0#SouthAfrica
EquatorialGuinea#0@1#Nigeria
SouthAfrica#0@0#SierraLeone
Nigeria#2@0#EquatorialGuinea
SouthAfrica#0@1#Nigeria
SierraLeone#2@1#EquatorialGuinea
EquatorialGuinea#0@1#SouthAfrica
Nigeria#4@1#SierraLeone
2010 FIFA World Cup qualification (CAF) 2nd round Group 6
4
Algeria
Gambia
Liberia
Senegal
12
Senegal#1@0#Algeria
Liberia#1@1#Gambia
Algeria#3@0#Liberia
Gambia#0@0#Senegal
Gambia#1@0#Algeria
Liberia#2@2#Senegal
Algeria#1@0#Gambia
Senegal#3@1#Liberia
Algeria#3@2#Senegal
Gambia#3@0#Liberia
Liberia#0@0#Algeria
Senegal#1@1#Gambia
2010 FIFA World Cup qualification (CAF) 2nd round Group 7
4
Botswana
Côted'Ivoire
Mozambique
12
Côted'Ivoire#1@0#Mozambique
Mozambique#1@2#Botswana
Botswana#1@1#Côted'Ivoire
Côted'Ivoire#4@0#Botswana
Mozambique#1@1#Côted'Ivoire
Botswana#0@1#Mozambique
2010 FIFA World Cup qualification (CAF) 2nd round Group 8
3
Mauritania
Morocco
Rwanda
6
Rwanda#3@0#Mauritania
Mauritania#1@4#Morocco
Rwanda#3@1#Morocco
Morocco#2@0#Rwanda
Mauritania#0@1#Rwanda
Morocco#4@1#Mauritania
2010 FIFA World Cup qualification (CAF) 2nd round Group 9
4
BurkinaFaso
Burundi
Seychelles
Tunisia
12
Burundi#1@0#Seychelles
Tunisia#1@2#BurkinaFaso
Seychelles#0@2#Tunisia
BurkinaFaso#2@0#Burundi
Seychelles#2@3#BurkinaFaso
Burundi#0@1#Tunisia
BurkinaFaso#4@1#Seychelles
Tunisia#2@1#Burundi
Seychelles#1@2#Burundi
BurkinaFaso#0@0#Tunisia
Tunisia#5@0#Seychelles
Burundi#1@3#BurkinaFaso
2010 FIFA World Cup qualification (CAF) 2nd round Group 10
4
Congo
Mali
Sudan
12
Mali#4@2#Congo
Congo#1@0#Sudan
Sudan#3@2#Mali
Mali#3@0#Sudan
Congo#1@0#Mali
Sudan#2@0#Congo
2010 FIFA World Cup qualification (CAF) 2nd round Group 11
3
Swaziland
Togo
Zambia
6
Togo#1@0#Zambia
Swaziland#2@1#Togo
Swaziland#0@0#Zambia
Zambia#1@0#Swaziland
Zambia#1@0#Togo
Togo#6@0#Swaziland
2010 FIFA World Cup qualification (CAF) 2nd round Group 12
4
CongoDR
Djibouti
Egypt
Malawi
12
Malawi#8@1#Djibouti
Egypt#2@1#CongoDR
Djibouti#0@4#Egypt
CongoDR#1@0#Malawi
Malawi#1@0#Egypt
CongoDR#5@1#Djibouti
Egypt#2@0#Malawi
Djibouti#0@3#Malawi
CongoDR#0@1#Egypt
Malawi#2@1#CongoDR
Egypt#4@0#Djibouti
Djibouti#0@6#CongoDR
Fck tournament
30
Team 0
Team 1
Team 2
Team 3
Team 4
Team 5
Team 6
Team 7
Team 8
Team 9
Team 10
Team 11
Team 12
Team 13
Team 14
Team 15
Team 16
Team 17
Team 18
Team 19
Team 20
Team 21
Team 22
Team 23
Team 24
Team 25
Team 26
Team 27
Team 28
Team 29
30
Team 0#1@0#Team 1
Team 1#1@0#Team 2
Team 2#1@0#Team 3
Team 3#1@0#Team 4
Team 4#1@0#Team 5
Team 5#1@0#Team 6
Team 6#1@0#Team 7
Team 7#1@0#Team 8
Team 8#1@0#Team 9
Team 9#1@0#Team 10
Team 10#1@0#Team 11
Team 11#1@0#Team 12
Team 12#1@0#Team 13
Team 13#1@0#Team 14
Team 14#1@0#Team 15
Team 15#1@0#Team 16
Team 16#1@0#Team 17
Team 17#1@0#Team 18
Team 18#1@0#Team 19
Team 19#1@0#Team 20
Team 20#1@0#Team 21
Team 21#1@0#Team 22
Team 22#1@0#Team 23
Team 23#1@0#Team 24
Team 24#1@0#Team 25
Team 25#1@0#Team 26
Team 26#1@0#Team 27
Team 27#1@0#Team 28
Team 28#1@0#Team 29
Team 29#1@0#Team 0

output
World Cup 1998 - Group A
1) Brazil 6p, 3g (2-0-1), 3gd (6-3)
2) Norway 5p, 3g (1-2-0), 1gd (5-4)
3) Morocco 4p, 3g (1-1-1), 0gd (5-5)
4) Scotland 1p, 3g (0-1-2), -4gd (2-6)

Some strange tournament
1) Team D 4p, 2g (1-1-0), 1gd (2-1)
2) Team E 3p, 2g (1-0-1), 0gd (3-3)
3) Team A 3p, 3g (0-3-0), 0gd (3-3)
4) Team B 1p, 1g (0-1-0), 0gd (1-1)
5) Team C 1p, 2g (0-1-1), -1gd (3-4)

Penultimate Tournament
1) A 6p, 2g (2-0-0), 3gd (3-0)
2) B 3p, 2g (1-0-1), 1gd (3-2)
3) C 3p, 3g (1-0-2), 1gd (3-2)
4) E 3p, 1g (1-0-0), 1gd (1-0)
5) D 0p, 2g (0-0-2), -6gd (0-6)

Last Tournament
1) Gato 2p, 2g (0-2-0), 0gd (5-5)
2) Mono 2p, 2g (0-2-0), 0gd (4-4)
3) Lobo 2p, 2g (0-2-0), 0gd (3-3)

2010 FIFA World Cup qualification (CAF) 2nd round Group 5
1) Ghana 12p, 6g (4-0-2), 6gd (11-5)
2) Gabon 12p, 6g (4-0-2), 5gd (8-3)
3) Libya 12p, 6g (4-0-2), 3gd (7-4)
4) Lesotho 0p, 6g (0-0-6), -14gd (2-16)

2010 FIFA World Cup qualification (CAF)
1) Madagascar 6p, 2g (2-0-0), 8gd (10-2)
2) Sierra Leone 4p, 2g (1-1-0), 1gd (1-0)
3) Djibouti 3p, 1g (1-0-0), 1gd (1-0)
4) Guinea-Bissau 1p, 2g (0-1-1), -1gd (0-1)
5) Somalia 0p, 1g (0-0-1), -1gd (0-1)
6) Comoros 0p, 2g (0-0-2), -8gd (2-10)

2010 FIFA World Cup qualification (CAF) 2nd round Group 1
1) Cameroon 16p, 6g (5-1-0), 12gd (14-2)
2) CapeVerde 9p, 6g (3-0-3), -1gd (7-8)
3) Tanzania 8p, 6g (2-2-2), 3gd (9-6)
4) Mauritius 1p, 6g (0-1-5), -14gd (3-17)

2010 FIFA World Cup qualification (CAF) 2nd round Group 2
1) Guinea 11p, 6g (3-2-1), 4gd (9-5)
2) Kenya 10p, 6g (3-1-2), 3gd (8-5)
3) Namibia 6p, 6g (2-0-4), -5gd (7-12)
4) Zimbabwe 6p, 6g (1-3-2), -2gd (4-6)

2010 FIFA World Cup qualification (CAF) 2nd round Group 3
1) Benin 12p, 6g (4-0-2), 4gd (12-8)
2) Angola 10p, 6g (3-1-2), 3gd (11-8)
3) Uganda 10p, 6g (3-1-2), -1gd (8-9)
4) Niger 3p, 6g (1-0-5), -6gd (5-11)

2010 FIFA World Cup qualification (CAF) 2nd round Group 4
1) Nigeria 18p, 6g (6-0-0), 10gd (11-1)
2) SouthAfrica 7p, 6g (2-1-3), 0gd (5-5)
3) SierraLeone 7p, 6g (2-1-3), -4gd (4-8)
4) EquatorialGuinea 3p, 6g (1-0-5), -6gd (4-10)

2010 FIFA World Cup qualification (CAF) 2nd round Group 6
1) Algeria 10p, 6g (3-1-2), 3gd (7-4)
2) Gambia 9p, 6g (2-3-1), 3gd (6-3)
3) Senegal 9p, 6g (2-3-1), 2gd (9-7)
4) Liberia 3p, 6g (0-3-3), -8gd (4-12)

2010 FIFA World Cup qualification (CAF) 2nd round Group 7
1) CÃ´ted'Ivoire 12p, 6g (3-3-0), 8gd (10-2)
2) Mozambique 8p, 6g (2-2-2), 2gd (7-5)
3) Madagascar 6p, 6g (1-3-2), -5gd (2-7)
4) Botswana 5p, 6g (1-2-3), -5gd (3-8)

2010 FIFA World Cup qualification (CAF) 2nd round Group 8
1) Morocco 9p, 4g (3-0-1), 6gd (11-5)
2) Rwanda 9p, 4g (3-0-1), 4gd (7-3)
3) Mauritania 0p, 4g (0-0-4), -10gd (2-12)

2010 FIFA World Cup qualification (CAF) 2nd round Group 9
1) BurkinaFaso 16p, 6g (5-1-0), 9gd (14-5)
2) Tunisia 13p, 6g (4-1-1), 8gd (11-3)
3) Burundi 6p, 6g (2-0-4), -4gd (5-9)
4) Seychelles 0p, 6g (0-0-6), -13gd (4-17)

2010 FIFA World Cup qualification (CAF) 2nd round Group 10
1) Mali 12p, 6g (4-0-2), 5gd (13-8)
2) Sudan 9p, 6g (3-0-3), 0gd (9-9)
3) Congo 9p, 6g (3-0-3), -1gd (7-8)
4) Chad 6p, 6g (2-0-4), -4gd (7-11)

2010 FIFA World Cup qualification (CAF) 2nd round Group 11
1) Zambia 7p, 4g (2-1-1), 1gd (2-1)
2) Togo 6p, 4g (2-0-2), 5gd (8-3)
3) Swaziland 4p, 4g (1-1-2), -6gd (2-8)

2010 FIFA World Cup qualification (CAF) 2nd round Group 12
1) Egypt 15p, 6g (5-0-1), 11gd (13-2)
2) Malawi 12p, 6g (4-0-2), 9gd (14-5)
3) CongoDR 9p, 6g (3-0-3), 8gd (14-6)
4) Djibouti 0p, 6g (0-0-6), -28gd (2-30)

Fck tournament
1) Team 0 3p, 2g (1-0-1), 0gd (1-1)
2) Team 1 3p, 2g (1-0-1), 0gd (1-1)
3) Team 10 3p, 2g (1-0-1), 0gd (1-1)
4) Team 11 3p, 2g (1-0-1), 0gd (1-1)
5) Team 12 3p, 2g (1-0-1), 0gd (1-1)
6) Team 13 3p, 2g (1-0-1), 0gd (1-1)
7) Team 14 3p, 2g (1-0-1), 0gd (1-1)
Team 15 3p, 2g (1-0-1), 0gd (1-1)
9) Team 16 3p, 2g (1-0-1), 0gd (1-1)
10) Team 17 3p, 2g (1-0-1), 0gd (1-1)
11) Team 18 3p, 2g (1-0-1), 0gd (1-1)
12) Team 19 3p, 2g (1-0-1), 0gd (1-1)
13) Team 2 3p, 2g (1-0-1), 0gd (1-1)
14) Team 20 3p, 2g (1-0-1), 0gd (1-1)
15) Team 21 3p, 2g (1-0-1), 0gd (1-1)
16) Team 22 3p, 2g (1-0-1), 0gd (1-1)
17) Team 23 3p, 2g (1-0-1), 0gd (1-1)
18) Team 24 3p, 2g (1-0-1), 0gd (1-1)
19) Team 25 3p, 2g (1-0-1), 0gd (1-1)
20) Team 26 3p, 2g (1-0-1), 0gd (1-1)
21) Team 27 3p, 2g (1-0-1), 0gd (1-1)
22) Team 28 3p, 2g (1-0-1), 0gd (1-1)
23) Team 29 3p, 2g (1-0-1), 0gd (1-1)
24) Team 3 3p, 2g (1-0-1), 0gd (1-1)
25) Team 4 3p, 2g (1-0-1), 0gd (1-1)
26) Team 5 3p, 2g (1-0-1), 0gd (1-1)
27) Team 6 3p, 2g (1-0-1), 0gd (1-1)
28) Team 7 3p, 2g (1-0-1), 0gd (1-1)
29) Team 8 3p, 2g (1-0-1), 0gd (1-1)
30) Team 9 3p, 2g (1-0-1), 0gd (1-1)

PS: This stupid site don't allow me to attach file.

cynthia cynthia
New poster
Posts: 1
Joined: Mon Oct 19, 2009 3:57 pm

### Re: 10194 - Football (aka Soccer)

To amishera : I have tested my code with the top 7 inputs provided by you,& I have checked my code for case insensitivity,it works.Still I dont know why I am getting WA. Can you please help me out.Here is my code
#include<iostream>
#include<cstdlib>
#include<vector>
#include<cstring>
using namespace std;
#include<ctype.h>
#define MIN(a,b) (a>b?b:a)

struct football
{
char name[30];
int pp,gam,w,lo,ti,gd,gs,ga;
};
football team[35];

int StrCmp(char temp[], char dummy[])
{
int i, l;
l = MIN(strlen(temp),strlen(dummy));
for(i = 0; i<l; i++) {
if(tolower(temp) > tolower(dummy)) return 1;
else if(tolower(temp) < tolower(dummy)) return -1;
}
if(strlen(temp)>strlen(dummy)) return 1;
else if(strlen(temp)<strlen(dummy)) return -1;
return 0;
}

int cmp(const void *a,const void *b)
{
football *x=(football *)a;
football *y=(football *)b;
if((x->pp)>(y->pp)) return -1;
else if((x->pp)<(y->pp)) return 1;
else
{
if((x->w)>(y->w)) return -1;
else if((x->w)<(y->w)) return 1;
else
{
if((x->gd)>(y->gd)) return -1;
else if((x->gd)<(y->gd)) return 1;
else
{
if((x->gs)>(y->gs)) return -1;
else if((x->gs)<(y->gs)) return 1;
else
{
if((x->gam)>(y->gam)) return 1;
else if((x->gam)<(y->gam)) return -1;
else
{
return StrCmp(x->name,y->name);

}

}

}
}
}

}

int main()
{
int N,i,j,k,Te,x,y,G,l,len1,len2;
char strT[100];

while(cin>>N)
{
char tourna[1000];
getchar();
int var=0;
while(N--)
{
gets(tourna);
if(!var) var=1;
else cout<<endl;
cin>>Te;
/*gets(strT);
sscanf(strT,"%d",&Te);*/
getchar();
char s[35];
for(x=0;x<Te;x++)
{
gets(s);
strcpy(team[x].name,s);
team[x].pp=0,team[x].gam=0,team[x].w=0,team[x].lo=0;
team[x].ti=0,team[x].gd=0,team[x].gs=0,team[x].ga=0;
}

cin>>G;
getchar();
for(x=1;x<=G;x++)
{
char t1[35],t2[35],no1[5],no2[5];
int p,n1,n2,f,g,h,m,n,r;
gets(s);
for(i=0,len1=0;i<strlen(s);i++)
{
if(s!='#') t1[len1++]=s;
else
{
t1[len1]='\0';
p=i;
break;
}

}
for(n=p+1,f=0;n<strlen(s);n++)
{
if(s[n]>='0'&&s[n]<='9') no1[f++]=s[n];
else
{
no1[f]='\0';
n1=atoi(no1);
h=n;
break;
}

}
for(m=h+1,g=0;m<strlen(s);m++)
{
if(s[m]>='0'&&s[m]<='9') no2[g++]=s[m];
else
{
no2[g]='\0';
n2=atoi(no2);
r=m;
break;
}

}
for(j=r+1,len2=0;j<strlen(s);j++)
{
t2[len2++]=s[j];
}
t2[len2]='\0';
if(n1>n2)
{
for(j=0;j<Te;j++)
{
if(strcmp(team[j].name,t1)==0)
{
team[j].pp+=3;
team[j].gam++;
team[j].w++;
team[j].gs+=n1;
team[j].ga+=n2;
}
if(strcmp(team[j].name,t2)==0)
{
// team[j].pp+=3;
team[j].gam++;
team[j].lo++;
team[j].gs+=n2;
team[j].ga+=n1;
}

}
}
else if(n1<n2)
{
for(j=0;j<Te;j++)
{
if(strcmp(team[j].name,t1)==0)
{
team[j].gam++;
team[j].lo++;
team[j].gs+=n1;
team[j].ga+=n2;
}
if(strcmp(team[j].name,t2)==0)
{
team[j].pp+=3;
team[j].gam++;
team[j].w++;
team[j].gs+=n2;
team[j].ga+=n1;
}

}
}
else
{
for(j=0;j<Te;j++)
{
if(strcmp(team[j].name,t1)==0)
{
team[j].pp++;
team[j].gam++;
team[j].ti++;
team[j].gs+=n1;
team[j].ga+=n2;
}
if(strcmp(team[j].name,t2)==0)
{
team[j].pp++;
team[j].gam++;
team[j].ti++;
team[j].gs+=n2;
team[j].ga+=n1;
}

}
}
}
for(j=0;j<Te;j++) team[j].gd=(team[j].gs-team[j].ga);

qsort(team,Te,sizeof(football),cmp);
cout<<tourna<<endl;
for(j=0;j<Te;j++)
{
//cout<<j+1<<") "<<team[j].name<<" "<<team[j].pp<<"p, "<<team[j].gam<<"g "<<"("<<team[j].w<<"-"<<team[j].ti<<"-"<<team[j].lo<<"), "<<team[j].gd<<"gd ("<<team[j].gs<<"-"<<team[j].ga<<")"<<endl;
printf("%d) %s %dp, %dg",j+1,team[j].name,team[j].pp,team[j].gam);
printf(" (%d-%d-%d), ",team[j].w,team[j].ti,team[j].lo);
printf("%dgd (%d-%d)\n",team[j].gd,team[j].gs,team[j].ga);
}

}
}
return 0;
}

zhangfei
New poster
Posts: 5
Joined: Thu Jul 29, 2010 2:08 pm

### 10194 - Football (aka Soccer)

???????????????????????????????????????????????????????????????????????WA??????????????????????????????AC????????

Code: Select all

``````#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

struct Team
{
char name[33];
char NAME[33];
int earn;
int game;
int win;
int tie;
int loss;
int gd;
int gs;
int ga;
};

Team tea[100];

bool compare(Team a,Team b)
{
if(a.earn != b.earn)
return a.earn > b.earn;
if(a.win != b.win)
return a.win > b.win;
if(a.gd != b.gd)
return a.gd > b.gd;
if(a.gs != b.gs)
return a.gs > b.gs;
if(a.game != b.game)
return a.game < b.game;
return strcmp(a.NAME,b.NAME) < 0;
}

void getInformation(int n,char * inf)
{
char tmp[110];
int i=0,j=0;
while(inf[i] != '#')
{
tmp[j++] = inf[i++];
}
tmp[j] = 0;
int aIndex = 0;
while(strcmp(tea[aIndex].name,tmp))
{
aIndex++;
}
int aScore = 0;
i++;
while(inf[i] != '@')
{
aScore = aScore * 10 + inf[i++] - '0';
}
i++;
int bScore = 0;
while(inf[i] != '#')
{
bScore = bScore * 10 + inf[i++] - '0';
}
i++;
strcpy(tmp,inf+i);
int bIndex = 0;
while(strcmp(tea[bIndex].name,tmp))
{
bIndex++;
}
if(aScore > bScore)
{
tea[aIndex].earn += 3;
tea[aIndex].win++;
tea[aIndex].gs += aScore;
tea[aIndex].ga += bScore;
tea[bIndex].loss++;
tea[bIndex].gs += bScore;
tea[bIndex].ga += aScore;
}
else if(aScore == bScore)
{
tea[aIndex].earn++;
tea[aIndex].tie++;
tea[aIndex].gs += aScore;
tea[aIndex].ga += bScore;
tea[bIndex].earn++;
tea[bIndex].tie++;
tea[bIndex].gs += bScore;
tea[bIndex].ga += aScore;
}
else
{
tea[bIndex].earn += 3;
tea[bIndex].win++;
tea[bIndex].gs += bScore;
tea[bIndex].ga += aScore;
tea[aIndex].loss++;
tea[aIndex].gs += aScore;
tea[aIndex].ga += bScore;
}
tea[aIndex].game++;
tea[bIndex].game++;
}

void changeName(int i)
{
int j=0;
while(tea[i].name[j])
{
if(tea[i].name[j]>='a' && tea[i].name[j]<='z')
tea[i].NAME[j] = tea[i].name[j] - 32;
else
tea[i].NAME[j] = tea[i].name[j];
j++;
}
}

int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif

int nCase;
scanf("%d\n",&nCase);
while(nCase--)
{
memset(tea,0,sizeof(tea));
char Name[110];
gets(Name);
puts(Name);
int T;
scanf("%d\n",&T);
int i;
for(i=0;i<T;i++)
{
gets(tea[i].name);
}
int G;
scanf("%d\n",&G);
char tmp[110];
for(i=0;i<G;i++)
{
gets(tmp);
getInformation(T,tmp);
}
for(i=0;i<T;i++)
{
tea[i].gd = tea[i].gs - tea[i].ga;
changeName(i);
}
sort(tea,tea+T,compare);
for(i=0;i<T;i++)
{
printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i+1,tea[i].name,tea[i].earn,tea[i].game,tea[i].win,tea[i].tie,tea[i].loss,tea[i].gd,tea[i].gs,tea[i].ga);
}
if(nCase)
putchar('\n');
}

return 0;
}

``````

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

### Re: 10194 - Football (aka Soccer)

1) Please use English
2) Search the board first using the search option at the top right corner
3) Make your post in an existing thread instead of creating a new one

nguyenh3
New poster
Posts: 5
Joined: Mon Sep 20, 2010 5:53 pm

### Re: 10194 - Football (aka Soccer)

This is getting repetitive but my code gets WA too.

Code: Select all

``````import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

Team[] teams;
Team team1, team2;
int number, goals1, goals2;
String[] game, string1, string2;
int tournaments = Integer.parseInt(scanner.nextLine());
while (tournaments > 0) {
System.out.println(scanner.nextLine());

number = Integer.parseInt(scanner.nextLine());
teams = new Team[number];

while (number-- > 0) {
teams[number] = new Team(scanner.nextLine());
}

number = Integer.parseInt(scanner.nextLine());
while (number-- > 0) {
game = scanner.nextLine().split("@");
string1 = game[0].split("#");
string2 = game[1].split("#");
goals1 = Integer.parseInt(string1[1]);
goals2 = Integer.parseInt(string2[0]);
team1 = findTeam(teams, string1[0]);
team2 = findTeam(teams, string2[1]);
team1.scored += goals1;
team2.scored += goals2;
team1.against += goals2;
team2.against += goals1;
team1.goalsDifference += goals1 - goals2;
team2.goalsDifference += goals2 - goals1;
team1.gamesPlayed++;
team2.gamesPlayed++;
if (goals1 == goals2) {
team1.tie();
team2.tie();
} else if (goals1 > goals2) {
team1.win();
team2.lose();
} else if (goals1 < goals2) {
team1.lose();
team2.win();
}
}

Arrays.sort(teams);

for (int i = 1; i <= teams.length; i++)
System.out.println(i + ") " + teams[i - 1]);

if (--tournaments > 0)
System.out.println();
}

scanner.close();
}

private static Team findTeam(Team[] teams, String name) {
for (int i = 0; i < teams.length; i++)
if (teams[i].name.equals(name))
return teams[i];
return null;
}

private static class Team implements Comparable<Team> {
final String name;
int wins, losses, ties;
int points, goalsDifference, gamesPlayed, scored, against;
Team(String name) {
this.name = name;
wins = losses = ties = points = scored = against = gamesPlayed = goalsDifference = 0;
}

void tie() {
ties++;
points++;
}

void win() {
wins++;
points += 3;
}

void lose() {
losses++;
points += 0;
}
/*
* a]) Team_name [b]p, [c]g ([d]-[e]-[f]), [g]gd ([h]-[i])
Where:
[a] = team rank
[b] = total points earned
[c] = games played
[d] = wins
[e] = ties
[f] = losses
[g] = goal difference
[h] = goals scored
[i] = goals against
*/
public String toString() {
return name + " " + points + "p, " + gamesPlayed + "g (" + wins + "-" + ties + "-" + losses + "), "
+ goalsDifference + "gd (" + scored + "-" + against + ")";
}

@Override
public int compareTo(Team t) {
if (t.points != this.points)
return t.points - this.points;

if (t.wins != this.wins)
return t.wins - this.wins;

if (t.goalsDifference != this.goalsDifference)
return t.goalsDifference - this.goalsDifference;

if (t.scored != this.scored)
return t.scored - this.scored;

if (t.gamesPlayed != this.gamesPlayed)
return this.gamesPlayed - t.gamesPlayed;

/*int dif = this.name.toLowerCase().compareTo(t.name.toLowerCase());
if (dif == 0)
dif = this.name.compareTo(t.name);
*/
return this.name.compareToIgnoreCase(t.name);
}
}
}
``````

clamhunter
New poster
Posts: 2
Joined: Mon Nov 01, 2010 6:47 am

### Re: 10194 - Football (aka Soccer)

My issue, which I'm embarrassed to say took me a very long time to find, was that there can be more than 9 goals in a game. The java code above also has this problem, you can't just parse a single character. You need to parse the strings between # and @ and @ and #