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

Postby animenologist » Tue Feb 05, 2008 5:52 am

The football.in thing is something I do when I program normally, having it read in from a default file. I use it to keep records, so that I have a record of all my input and give them proper names to go with the program. When I submit, I switch the files to System.in for standard input.

Anyways, this is my newest code (with the normal standard input this time)

Code: Select all

import java.io.*;
import java.util.*;

public class Main implements Comparable<Main>{
   
   public String name, reducedName;
   public int points, wins, losses, ties, scored, against, played;
   
   public Main(String x){
      this.name = x;
      this.points = 0;
      this.wins = 0;
      this.losses = 0;
      this.ties = 0;
      this.scored = 0;
      this.against = 0;
      this.played = 0;
   }
   
   public int compareTo(Main x){
      
      if(this.points != x.points)
         return x.points-this.points;      
      if(this.wins != x.wins)
         return x.wins-this.wins;      
      if((this.scored-this.against) != (x.scored-x.against))
         return ((x.scored-x.against) - (this.scored-this.against) );      
      if(this.scored != x.scored)
         return x.scored-this.scored;      
      if(this.played != x.played)
         return this.played-x.played;      
      return this.stringCompare(x.name);

   }
   
   public int stringCompare(String x){
      
      for(int a = 0;a < Math.min(this.name.length(), x.length());a++){
         if(Character.isLetter(this.name.charAt(a)) && Character.isLetter(x.charAt(a))){
            if(Character.toUpperCase(this.name.charAt(a)) != Character.toUpperCase(x.charAt(a)))
               return Character.toUpperCase(this.name.charAt(a))-Character.toUpperCase(x.charAt(a));
         }
         else{
            if(this.name.charAt(a) != x.charAt(a))
               return this.name.charAt(a)-x.charAt(a);
         }
      }
      
      return this.name.length()-x.length();
   }
   
   public static void main(String[] args)throws Exception{
      
      Scanner In = new Scanner(System.in);
      TreeMap<String, Integer> mapping;
      int numGames = Integer.parseInt(In.nextLine());
      
      for(int currGame = 0;currGame < numGames;currGame++){
         String tournament = In.nextLine();
         int numTeams = Integer.parseInt(In.nextLine());
         mapping = new TreeMap<String, Integer>();
         Main teams[] = new Main[numTeams];
         for(int currTeam = 0;currTeam < numTeams;currTeam++){
            String teamName = In.nextLine();
            teams[currTeam] = new Main(teamName);
            mapping.put(teamName, new Integer(currTeam));
         }
         int numMatches = Integer.parseInt(In.nextLine());
         for(int currMatch = 0;currMatch < numMatches;currMatch++){
            String game = In.nextLine();
            String teamOne = game.substring(0, game.indexOf("#"));
            game = game.substring(game.indexOf("#")+1);
            int scoreOne = Integer.parseInt(game.substring(0, game.indexOf("@")));
            game = game.substring(game.indexOf("@")+1);
            int scoreTwo = Integer.parseInt(game.substring(0, game.indexOf("#")));
            game = game.substring(game.indexOf("#")+1);
            String teamTwo = game;
            teams[mapping.get(teamOne).intValue()].scored+= scoreOne;
            teams[mapping.get(teamOne).intValue()].against+= scoreTwo;
            teams[mapping.get(teamOne).intValue()].played++;
            teams[mapping.get(teamTwo).intValue()].scored+= scoreTwo;
            teams[mapping.get(teamTwo).intValue()].against+= scoreOne;
            teams[mapping.get(teamTwo).intValue()].played++;
            if(scoreOne > scoreTwo){
               teams[mapping.get(teamOne).intValue()].wins++;
               teams[mapping.get(teamOne).intValue()].points+= 3;
               teams[mapping.get(teamTwo).intValue()].losses++;
            }
            else if(scoreTwo > scoreOne){
               teams[mapping.get(teamTwo).intValue()].wins++;
               teams[mapping.get(teamTwo).intValue()].points+= 3;
               teams[mapping.get(teamOne).intValue()].losses++;               
            }
            else{
               teams[mapping.get(teamOne).intValue()].ties++;
               teams[mapping.get(teamOne).intValue()].points++;
               teams[mapping.get(teamTwo).intValue()].ties++;
               teams[mapping.get(teamTwo).intValue()].points++;
            }
         }
         Arrays.sort(teams);
         if(currGame!=0)
            System.out.println();
         System.out.println(tournament);
         for(int currTeam = 0;currTeam < numTeams;currTeam++){
            System.out.println((currTeam+1)+") "+teams[currTeam].name+" "+teams[currTeam].points+"p, "+      
            teams[currTeam].played+"g ("+teams[currTeam].wins+"-"+teams[currTeam].ties+"-"+teams[currTeam].losses+"), "+
            (teams[currTeam].scored-teams[currTeam].against)+"gd ("+teams[currTeam].scored+"-"+teams[currTeam].against+")");
         }
      }
   }
   
}



If my problem was truly the difference in cases and the characters between the two cases, I created this new function

Code: Select all

   public int stringCompare(String x){
      
      for(int a = 0;a < Math.min(this.name.length(), x.length());a++){
         if(Character.isLetter(this.name.charAt(a)) && Character.isLetter(x.charAt(a))){
            if(Character.toUpperCase(this.name.charAt(a)) != Character.toUpperCase(x.charAt(a)))
               return Character.toUpperCase(this.name.charAt(a))-Character.toUpperCase(x.charAt(a));
         }
         else{
            if(this.name.charAt(a) != x.charAt(a))
               return this.name.charAt(a)-x.charAt(a);
         }
      }
      
      return this.name.length()-x.length();
   }


It goes through each character and checks if they're both letters. If so, changes them both to uppercase and compares. If not, compares them as normal. If they are lexicographically equal up to the length of the shortest string, it gives precedence for the shorter of the 2. So what this means is that a > [ > A == a. But still, a WA. Can't think of what else could be wrong.
animenologist
New poster
 
Posts: 7
Joined: Tue Jan 22, 2008 5:55 am

Postby yiuyuho » Tue Feb 05, 2008 7:03 pm

What is wrong is that you're actually doing it the right way. Do your case insensitive compare as follows: change all uppercase to lowercase then use regular string compare.
yiuyuho
A great helper
 
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States

Postby animenologist » Sat Feb 09, 2008 4:50 pm

Tried everything. Tried toLowercase comparison, toUpperCase comparison, compareToIgnoreCase, and my own function. Tried trimming, not trimming, removing leading whitespace. Nothing seems to be working. Is there any logical errors with my comparisons? I think I'm following the rules correctly.
animenologist
New poster
 
Posts: 7
Joined: Tue Jan 22, 2008 5:55 am

Postby yiuyuho » Sun Feb 10, 2008 3:03 pm

Everything looks right......may be try to do it in C++? I know in the old days, if java gives a RE sometimes it's reported as WA, as the judge would read the error messages as the output of your program. But I am not sure if that's still true after the upgrade...probably not.
yiuyuho
A great helper
 
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States

Re: 10194 - Football (aka Soccer) Why WA?

Postby tiagowanderley » Fri Jun 20, 2008 5:27 pm

Hi,
my program is calculating everything correct. I'm receiving AW, I'm almost sure que is because of the lexicographical order. My program is written in java. Below it is the code .

Code: Select all
   import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

class Main {
   public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
      int qntCamp = in.nextInt();
      in.nextLine();
      HashMap<String,Team> times;
      String[] team1, team2;
      for (int i = 0; i < qntCamp; i++) {
         Object teams[];
         times = new HashMap<String,Team>();
         String nomeCamp = in.nextLine();
         int qntTimes = in.nextInt();
         in.nextLine();
         for (int j = 0; j < qntTimes; j++) {
            String time = in.nextLine();
            times.put(time,new Team(time));
         }
         int qntJogos = in.nextInt();
         in.nextLine();
         for (int j = 0; j < qntJogos; j++) {
            String jogo = in.nextLine();
            String placar[] = jogo.split("@");            
            team1 = placar[0].split("#");            
            team2 = placar[1].split("#");
            atualizaDados(team1[0],Integer.parseInt(team1[1]),times.get(team1[0]),team2[1],Integer.parseInt(team2[0]),times.get(team2[1]),times);
         }
         teams = times.values().toArray();
         Arrays.sort(teams);   
         System.out.println(nomeCamp);
         for (int k = 0; k < teams.length; k++) {
            Team t = (Team)teams[k];
            int n = k+1;
            System.out.println(t.toString(n));
         }   
         System.out.println();
      }
   }

   public static void atualizaDados(String time1, int golsT1, Team t1,
         String time2, int golsT2, Team t2,HashMap<String,Team> times) {
      times.get(time1).setGolsContra(golsT2);
      times.get(time1).setGolspro(golsT1);
      times.get(time1).setSaldoGols();
      times.get(time1).setQntJogos();
      times.get(time2).setGolsContra(golsT1);
      times.get(time2).setGolspro(golsT2);
      times.get(time2).setSaldoGols();
      times.get(time2).setQntJogos();
      if(golsT1 > golsT2){
         times.get(time1).setPontos(3);
         times.get(time1).setVitorias();
         times.get(time2).setDerrotas();
      }
      else if(golsT2 > golsT1){
         times.get(time2).setPontos(3);
         times.get(time2).setVitorias();
         times.get(time1).setDerrotas();
      }
      else{
         times.get(time1).setPontos(1);
         times.get(time2).setPontos(1);
         times.get(time1).setEmpate();
         times.get(time2).setEmpate();
      }

   }
}

class Team implements Comparable<Object>{
   int pontos, vitorias, golspro, golsContra, saldoGols, qntJogos,empate,derrotas;
   String nome;
   public Team(String nome){
      this.nome = nome;
      this.vitorias = 0;
      this.golspro = 0;
      this.golsContra = 0;
      this.saldoGols = 0;
      this.qntJogos = 0;
      this.empate = 0;
      this.derrotas = 0;

   }

   public int getPontos() {
      return pontos;
   }

   public void setPontos(int pontos) {
      this.pontos += pontos;
   }

   public int getVitorias() {
      return vitorias;
   }

   public void setVitorias() {
      this.vitorias++;
   }

   public int getGolspro() {
      return golspro;
   }

   public void setGolspro(int golspro) {
      this.golspro += golspro;
   }

   public int getGolsContra() {
      return golsContra;
   }

   public void setGolsContra(int golsContra) {
      this.golsContra += golsContra;
   }

   public int getSaldoGols() {
      return saldoGols;
   }

   public void setSaldoGols() {
      this.saldoGols = this.golspro - this.golsContra;
   }

   public int getQntJogos() {
      return qntJogos;
   }

   public void setQntJogos() {
      this.qntJogos++;;
   }

   public int compareTo(Object o) {
      Team t = (Team) o;
      if(t.getPontos() > pontos)
         return 1;
      else if(t.getPontos() < pontos)
         return -1;
      else if(t.getVitorias() > vitorias)
         return 1;
      else if(t.getVitorias() < vitorias)
         return -1;
      else if(t.getSaldoGols() > saldoGols)
         return 1;
      else if(t.getSaldoGols() < saldoGols)
         return -1;
      else if(t.getGolspro() > golspro)
         return 1;
      else if(t.getGolspro() < golspro)
         return -1;
      else if(t.getQntJogos() > qntJogos)
         return -1;
      else if(t.getQntJogos() < qntJogos)
         return 1;
      else{
         int min = Math.min(t.getNome().length(),nome.length());
         String tUP = t.getNome().toUpperCase();
         String nUP = nome.toUpperCase();
         int retorno = 0;
         for (int i = 0; i < min; i++) {
            if(tUP.charAt(i) == nUP.charAt(i)){
                  if(t.getNome().charAt(i) > nome.charAt(i))
                     retorno = -1;
                  else if(t.getNome().charAt(i) < nome.charAt(i))
                     retorno = 1;   
            }
            else{
               if(tUP.charAt(i) > nUP.charAt(i))
                  return -1;
               else if(tUP.charAt(i) < nUP.charAt(i))
                  return 1;
            }
            if(t.getNome().length() > nome.length() && retorno == 0)
               return 1;
            else if (t.getNome().length() < nome.length() && retorno == 0)
                return -1;
            
         }
         return retorno;
      }
   }

   public String getNome() {
      return nome;
   }

   public void setNome(String nome) {
      this.nome = nome;
   }

   public String toString(int num){
      return (num + ") "+this.nome + " " + this.pontos+"p,"+" "+qntJogos+"g"+" ("+vitorias+"-"+empate+"-"+derrotas+"), "+saldoGols+"gd ("+golspro+"-"+golsContra+")");
   }

   public int getEmpate() {
      return empate;
   }

   public void setEmpate() {
      this.empate++;
   }

   public int getDerrotas() {
      return derrotas;
   }

   public void setDerrotas() {
      this.derrotas++;
   }
}


Help-me please.
tiagowanderley
New poster
 
Posts: 4
Joined: Thu May 01, 2008 3:49 pm

Re:

Postby stcheung » Wed Oct 08, 2008 3:17 am

AliSaleh wrote:Hello
I have tested may code against a lot of test cases but it still WA
I don't know what to do If any one can help me this is my code.
sorry it's long .

Code: Select all
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <vector>
using namespace std;
struct team{
   int play; int win;
   int loss; int tie;
   int gin; int gout;
   int point; string name;
   string realName;
};
struct class1{
public :
   bool operator()(team t1,team t2){
      if(t1.point!=t2.point)
         return t1.point>t2.point;
      else if(t1.win!=t2.win)
         return t1.win>t2.win;
      else if((t1.gout-t1.gin)!=(t2.gout-t2.gin))
         return (t1.gout-t1.gin)>(t2.gout-t2.gin);
      else if(t1.gout!=t2.gout)
         return t1.gout>t2.gout;
      else if(t1.play!=t2.play)
         return t1.play<t2.play;
      else
         return lexicographical_compare(t1.name.begin(),t1.name.end(),t2.name.begin(),t2.name.end());
   }
}comparison;

map<string,team> mp;

int main()
{
   string str,all,team1,team2,goal="",title1,name;
   team temp;
   int N,T,G;
   int first,second1,g1,g2;
   vector<team> temp2;
   map<string,team>::iterator team_1;
   map<string,team>::iterator team_2;
   
   temp.gin=temp.gout=temp.loss=temp.win=temp.tie=temp.play=temp.point=0;
   temp.name="";
   cin>>N;
   for(N;N>0;N--){
      cin.ignore();
      char title[101];
      cin.getline(title,101);
      title1=title;
      cin>>T;
      for(T;T>0;T--){
         cin.ignore();
         char ch[31];
         cin.get(ch,31);
         name=str=ch;
         for(int i=0;i<(int)team1.size();i++)
            name[i]=tolower(str[i]);
         temp.name=name;
         mp.insert(make_pair(str,temp));
      }
      cin>>G;
      for(G;G>0;G--){
         cin.ignore();
         char ch[70];
         cin.get(ch,70);
         all=ch;
         first=(int)all.find("#");
         second1=(int)all.rfind("#");
         team1.insert(0,all,0,first);
         team2.insert(0,all,second1+1,all.size()-1+second1);
         first++;
         while(all[first]!='@'){
            goal+=all[first];
            first++;
         }
         g1=atoi(goal.c_str());
         goal="";
         first++;
         while(first!=second1){
            goal+=all[first];
            first++;
         }
         g2=atoi(goal.c_str());
         goal="";
         
         team_1=mp.find(team1);
         team_2=mp.find(team2);
         if(g1>g2){
            team_1->second.win++;
            team_2->second.loss++;}
         else if(g2>g1){
            team_1->second.loss++;
            team_2->second.win++;}
         else{
            team_1->second.tie++;
            team_2->second.tie++;
         }
         
         team_1->second.play++;
         team_1->second.gout+=g1;
         team_1->second.gin+=g2;
         team_1->second.point=team_1->second.win*3+team_1->second.tie*1;
         team_1->second.realName=team1;
         
         team_2->second.play++;
         team_2->second.gout+=g2;
         team_2->second.gin+=g1;
         team_2->second.point=team_2->second.win*3+team_2->second.tie*1;
         team_2->second.realName=team2;
         
         team1="";
         team2="";
         
      }
      team_1=mp.begin();
      while(team_1!=mp.end()){
         temp2.push_back(team_1->second);
         team_1++;
      }
      sort(temp2.begin(),temp2.end(),comparison);
      cout<<title1<<endl;
      for(int x=0;x<(int)temp2.size();x++){
         cout<<x+1<<") "<<temp2[x].realName<<" "<<temp2[x].point<<"p, ";
         cout<<temp2[x].play<<"g "<<"("<<temp2[x].win<<"-"<<temp2[x].tie;
         cout<<"-"<<temp2[x].loss<<"), "<<(temp2[x].gout-temp2[x].gin)<<"gd (";
         cout<<temp2[x].gout<<"-"<<temp2[x].gin<<")";
         if(x!=(int)temp2.size()-1)
            cout<<endl;
      }
      if(N!=1)
         cout<<endl<<endl;
      title1="";
      mp.clear();
      temp2.clear();
   }
   return 0;
}


EDIT by moderator : Use code tags.


Thanks for your program. I had no luck getting my Java program to be accepted even though it passes all the test cases here and that I read every single thread couple times already. I also double checked my code 10 times and tried all the different variations of "case-insensitive" comparisons (convert to lowercase first, convert to uppercase first, only convert when both characters are letters). Still no luck so I suspect it's some Java-specific issue. Did ANYONE get accepted with a Java solution?

So I decided to do it in C++ but my C++ is rusty so I took your program and got accepted after fixing the bugs in it. There are couple bugs, all pretty obvious in my opinion:
(1) You missed a new line at the end
(2) You set the realName variable ONLY when the team is referenced in the list of games. This is unnecessary. Simply set the realName variable when you are reading the list of team names.
(3) You are doing a case-sensitive comparison. Instead, you should first convert both strings to uppercase and then call the lexicographical_compare() on them. In fact, converting both to lowercase would also work.

Normally I would consider it unethical to get AC by tweaking someone else's program. But in this case I feel like I know the problem in-and-out so I don't feel so guilty about it. I just suspect if anyone can really get accepted in Java!!!
stcheung
Experienced poster
 
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am

Re: 10194 - Football (aka Soccer)

Postby stcheung » Wed Oct 08, 2008 3:25 am

Here's my code in Java. It looks long but half of it is just helper methods. Actual code is <120 lines. Java is such an expressive language (esp 1.6)

Code: Select all
import java.io.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;

class Main {
   static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));   
   static int[] intBuffer = new int[0];
   static int intBufferPos = 0;
   static double[] doubleBuffer = new double[0];
   static int doubleBufferPos = 0;
   static StringBuilder outputBuffer = new StringBuilder(10000);
   static Scanner scanner = new Scanner(new BufferedInputStream(System.in));
   
   static int[] readIntArr() throws Exception {
      while(true) {
         String line = readLine();
         if(line == null)
            return null;
         else if(line.equals(""))
            continue;
         else return toIntArr(line);
      }
   }
   
   static int[] toIntArr(String str) {
      if(str.equals(""))
         return new int[0];
      
      String strArr[] = toStrArr(str);
      int intArr[] = new int[strArr.length];
      for(int i=0; i<strArr.length; i++)
         intArr[i] = toInt(strArr[i]);
      
      return intArr;
   }
   
   static int readInt() throws Exception {
      while(intBufferPos >= intBuffer.length) {
         intBuffer = readIntArr();
         intBufferPos = 0;
      }
      return intBuffer[intBufferPos++];
   }
   
   static int toInt(String str) {
      return Integer.parseInt(str);
   }
   
   static long toLong(String str) {
      return Long.parseLong(str);
   }
   
   static double[] readDoubleArr() throws Exception {
      while(true) {
         String line = readLine();
         if(line == null)
            return null;
         else if(line.equals(""))
            continue;
         else return toDoubleArr(line);
      }
   }
   
   static double[] toDoubleArr(String str) {
      if(str.equals(""))
         return new double[0];
      
      String strArr[] = toStrArr(str);
      double doubleArr[] = new double[strArr.length];
      for(int i=0; i<strArr.length; i++)
         doubleArr[i] = toDouble(strArr[i]);
      
      return doubleArr;
   }
   
   static double readDouble() throws Exception {
      while(doubleBufferPos >= doubleBuffer.length) {
         doubleBuffer = readDoubleArr();
         doubleBufferPos = 0;
      }
      return doubleBuffer[doubleBufferPos++];
   }
   
   static double toDouble(String str) {
      return Double.parseDouble(str);
   }
   
   static String[] toStrArr(String str) {
      StringTokenizer st = new StringTokenizer(str);
      String strArr[] = new String[st.countTokens()];
      int i=0;
      while(st.hasMoreTokens()) {
         strArr[i++] = st.nextToken();
      }
      return strArr;
   }
   
   static String[] readStrArr() throws Exception {
      while(true) {
         String line = readLine();
         if(line == null)
            return null;
         else if(line.equals(""))
            continue;
         return toStrArr(line);
      }
   }
   
   static String readLine() throws Exception {      
      return br.readLine();
   }
   
   static boolean isEmpty(String s) {
      return (s == null || s.equals(""));
   }
   
   static void flush() {
      System.out.print(outputBuffer.toString());
      outputBuffer = new StringBuilder(10000);
   }
   
   static void print(int n) {
      outputBuffer.append(n);
   }
   
   static void print(long n) {
      outputBuffer.append(n);
   }
   
   static void print(char ch) {
      outputBuffer.append(ch);
   }
   
   static void print(String s) {
      outputBuffer.append(s);
   }
   
   static void println() {
      outputBuffer.append("\n");
   }
   
   static void println(int n) {
      outputBuffer.append(n + "\n");
   }
   
   static void println(long n) {
      outputBuffer.append(n + "\n");
   }
   
   static void println(String s) {
      outputBuffer.append(s + "\n");
   }
   
   static int max(int a, int b) {
      return (a>=b ? a : b);
   }
   
   static int min(int a, int b) {
      return (a<b ? a : b);
   }
   
   static long abs(long n) {
      return Math.abs(n);
   }
   
   static void myassert(boolean b) throws Exception {
      if(!b)
         throw new Exception("BAD");
   }
   
   class TeamStat implements Comparable<TeamStat> {
      public String name = null;
      public int played = 0;
      public int wins = 0;
      public int ties = 0;
      public int losses = 0;
      public int goalsScored = 0;
      public int goalsAgainst = 0;
      
      public TeamStat(String _name) {
         name = _name;
      }
      
      public int TotalPoints() {
         return 3*wins + 1*ties;
      }
      
      public int GoalDifference() {
         return goalsScored - goalsAgainst;         
      }
      
      public int compareTo(TeamStat ts2) {
         int totalPoints = TotalPoints();
         int totalPoints2 = ts2.TotalPoints();
         int goalDifference = GoalDifference();
         int goalDifference2 = ts2.GoalDifference();
         if(totalPoints > totalPoints2)
            return -1;
         else if(totalPoints < totalPoints2)
            return 1;
         else if(wins > ts2.wins)
            return -1;
         else if(wins < ts2.wins)
            return 1;
         else if(goalDifference > goalDifference2)
            return -1;
         else if(goalDifference < goalDifference2)
            return 1;
         else if(goalsScored > ts2.goalsScored)
            return -1;
         else if(goalsScored < ts2.goalsScored)
            return 1;
         else if(played < ts2.played)
            return -1;
         else if(played > ts2.played)
            return 1;
         
         return (name.toUpperCase().compareTo(ts2.name.toUpperCase()));
      }
   }
   
   public static void main(String args[]) throws Exception {
      int C = readInt();
      Main m = new Main();
      for(int c=1; c<=C; c++) {
         String tournament = readLine();
         
         ArrayList<TeamStat> stats = new ArrayList<TeamStat>();
         HashMap<String, Integer> teams = new HashMap<String, Integer>();
         
         int T = readInt();
         for(int t=0; t<T; t++) {
            String teamname = readLine();
            stats.add(m.new TeamStat(teamname));
            teams.put(teamname, t);
         }
         
         int G = readInt();
         for(int g=0; g<G; g++) {
            String game = readLine();
            String strArr[] = game.split("#");
            int teamIndex = teams.get(strArr[0]);            
            int team2Index = teams.get(strArr[2]);
            myassert(teamIndex != team2Index);
            String result[] = strArr[1].split("@");
            int goals = toInt(result[0]);
            int goals2 = toInt(result[1]);
            
            TeamStat team = stats.get(teamIndex);
            TeamStat team2 = stats.get(team2Index);
            team.played++;
            team2.played++;
            team.goalsScored += goals;
            team.goalsAgainst += goals2;
            team2.goalsScored += goals2;
            team2.goalsAgainst += goals;
            if(goals > goals2) {
               team.wins++;
               team2.losses++;
            } else if(goals < goals2) {
               team.losses++;
               team2.wins++;
            } else {
               team.ties++;
               team2.ties++;
            }
         }
         
         Collections.sort(stats);
         
         if(c>1)
            println();
         
         println(tournament);
         int ranking = 1;
         for(TeamStat team : stats) {
            print(ranking);
            print(") " + team.name + " " + team.TotalPoints() + "p, " + team.played + "g ");
            print("(" + team.wins + "-" + team.ties + "-" + team.losses + "), ");
            println(team.GoalDifference() + "gd (" + team.goalsScored + "-" + team.goalsAgainst + ")");
            ranking++;
         }
         flush();
      }
   }
}
stcheung
Experienced poster
 
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am

Re: 10194 - Football (aka Soccer)

Postby JohnTortugo » Tue Oct 14, 2008 5:47 pm

Hi guys, i'm getting lots of W.A in this problem, i really dont know what's wrong with my code. I'll be glad by any help.

Thanks in advance.

Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <inttypes.h>
#include <ctype.h>
#include <algorithm>
#include <map>
#include <utility>
#include <iostream>

#define TRACE(x...)
#define PRINT(x...) TRACE(printf(x))
#define WATCH(x) TRACE(cout << #x" = " << x << "\n")
#define _inline(f...) f() __attribute__((always_inline)); f
#define _foreach(it, b, e) for (typeof(b) it = (b); it != (e); it++)
#define foreach(x...) _foreach(x)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

const int INF = 0x3F3F3F3F;
const int NULO = -1;
const double EPS = 1e-10;

using namespace std;

/*--------------------------------------------------------------*/

#define    MAX_EQUIPE_NAME    150
#define      MAX_TIMES         35

typedef struct {
      char nome[MAX_EQUIPE_NAME];
      int oleitura;
      int pontos;
      int vitorias;
      int derrotas;
      int empates;
      int gols_pros;
      int gols_cont;
} equipe;

equipe * initTime(string nomeTime, int order);
int cmpScore(const void *timea, const void *timeb);
void strToUpper(char *str);

_inline(int cmp)(double x, double y = 0, double tol = EPS) {
   return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

int main() {

   int ncamps;      /* numero de campeonatos */
   int ntimes;      /* numero de times */
   int njogos;      /* numero de jogos */
   int golsa, golsb;   /* gols marcados por a e por b */
   int rank;      /* rank do time */
   
   string nomeTime;
   string nomeCamp;
   
   map<string, equipe *> times;
   map<string, equipe *>::iterator it;

   equipe resultado[MAX_TIMES];
   
   char equipea[MAX_EQUIPE_NAME], equipeb[MAX_EQUIPE_NAME];

   cin >> ncamps;
   cin.ignore();
   
   for (int i=0; i<ncamps; i++) {
      times.clear();

      getline(cin, nomeCamp);      /* nome do campeonato */
      //cout << "Nome Camp: " << nomeCamp << endl;
      
      cin >> ntimes;   /* quantos times */
      cin.ignore();
      //cout << "Num times: " << ntimes << endl;
      
      for (int j=0; j<ntimes; j++) {
         getline(cin, nomeTime);
         times[nomeTime] = initTime(nomeTime, j);
         //cout << "\t" << nomeTime << endl;
      }
   
      cin >> njogos;   /* quantos jogos jogados */
      cin.ignore();
      //cout << "Jogos: " << njogos << endl;

      for (int k=0; k<njogos; k++) {
         scanf("%[^#]#%d@%d#%[^\n]\n", equipea, &golsa, &golsb, equipeb);
         //printf("\t%s %d --- %s %d\n", equipea, golsa, equipeb, golsb);

         equipe *timea = times[equipea];
         equipe *timeb = times[equipeb];

         if (golsa > golsb) {   /* time-1 ganhou */
            timea->pontos += 3;
            timea->vitorias += 1;
            timea->gols_pros += golsa;
            timea->gols_cont += golsb;

            timeb->derrotas += 1;
            timeb->gols_pros += golsb;
            timeb->gols_cont += golsa;
         }
         else if (golsa < golsb) {   /* time-2 ganhou */
            timeb->pontos += 3;
            timeb->vitorias += 1;
            timeb->gols_pros += golsb;
            timeb->gols_cont += golsa;

            timea->derrotas += 1;
            timea->gols_pros += golsa;
            timea->gols_cont += golsb;
         }
         else {   /* empate */
            timea->pontos += 1;
            timeb->pontos += 1;

            timea->empates += 1;
            timeb->empates += 1;

            timea->gols_pros += golsa;
            timea->gols_cont += golsb;

            timeb->gols_pros += golsb;
            timeb->gols_cont += golsa;
         }
      }

      /* copia os dados para um vetor, para ordena-los */
      for (it=times.begin(), rank=0; it!=times.end(); it++, rank++) {
            equipe *time = it->second;
            resultado[rank] = *time;
      }

      qsort(resultado, ntimes, sizeof(equipe), cmpScore);

      /* Imprime o ranking */
      printf("%s\n", nomeCamp.c_str());
      for (rank=0; rank<ntimes; rank++) {
            equipe time = resultado[rank];
            printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", rank+1, time.nome, time.pontos, time.derrotas+time.empates+time.vitorias, time.vitorias, time.empates, time.derrotas, time.gols_pros - time.gols_cont, time.gols_pros, time.gols_cont);      
      }
      printf("\n");
   }

   return 0;
}

equipe * initTime(string nomeTime, int order) {
   equipe *t = (equipe *) malloc(sizeof(equipe));
       
   strcpy(t->nome, nomeTime.c_str());
   t->oleitura = order;
   t->pontos = 0;
   t->vitorias = 0;
   t->derrotas = 0;
   t->empates = 0;
   t->gols_pros = 0;
   t->gols_cont = 0;
   
   return t;
}

void strToLower(char *str) {
    std::transform(str, str+sizeof(str)/sizeof(char), str, (int(*)(int)) tolower);
}

int cmpScore(const void *timea, const void *timeb) {
   equipe *ea = (equipe *) timea;
   equipe *eb = (equipe *) timeb;

   int difa = ea->gols_pros - ea->gols_cont;
   int difb = eb->gols_pros - eb->gols_cont;

   int ja = ea->vitorias + ea->derrotas + ea->empates;
   int jb = eb->vitorias + eb->derrotas + eb->empates;

   char nomea[MAX_EQUIPE_NAME];
   char nomeb[MAX_EQUIPE_NAME];

   if (ea->pontos != eb->pontos) return eb->pontos - ea->pontos;

   if (ea->vitorias != eb->vitorias) return eb->vitorias - ea->vitorias;

   if (difa != difb) return difb - difa;

   if (ea->gols_pros != eb->gols_pros) return eb->gols_pros - ea->gols_pros;

   if (ja != jb) return ja-jb;

   strcpy(nomea, ea->nome);
   strcpy(nomeb, eb->nome);

   strToLower(nomea);
   strToLower(nomeb);

   return strcmp(nomea, nomeb);
}
JohnTortugo
New poster
 
Posts: 16
Joined: Sun Jul 20, 2008 7:05 pm

Re: 10194 - Football (aka Soccer)

Postby JohnTortugo » Mon Oct 20, 2008 4:53 am

No one know what is wrong with my code? I think it's a little mistake...

Thanks.
JohnTortugo
New poster
 
Posts: 16
Joined: Sun Jul 20, 2008 7:05 pm

Re: 10194 - Football (aka Soccer)

Postby L I M O N » Sun Nov 02, 2008 6:00 am

find your bug here : http://www.youngprogrammer.com
L I M O N
Learning poster
 
Posts: 58
Joined: Wed Dec 31, 2003 8:43 am
Location: Dhaka, Bangladesh

Re: 10194 - Football (aka Soccer)

Postby JohnTortugo » Sun Nov 02, 2008 5:59 pm

Hi all.

thanks LIMON. I found my error, it was a "\n" at the end of output. I used only strcasecmp....

But now I'm confused... this shouldn't be a Presentation Error (the "\n" at the end)?

thanks. John.
JohnTortugo
New poster
 
Posts: 16
Joined: Sun Jul 20, 2008 7:05 pm

Re: 10194 - Football (aka Soccer)

Postby ergysr » Wed Jan 14, 2009 4:28 pm

Be careful, it's not only the case insensitive comparison to mind. There should be a blank line BETWEEN each case. So a '\n' after the last case should be avoided as it gives WA.
ergysr
New poster
 
Posts: 9
Joined: Sun Oct 07, 2007 1:25 pm

Re: 10194 - Football (aka Soccer)

Postby assasin » Thu Mar 19, 2009 3:28 am

I do not understand what to do with this problem. Getting WA continuously.
Here goes my code
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


typedef struct{
   char name[32];
   int point;
   int numGame;
   int numWin;
   int numTie;
   int numLoss;
   int goalScored;
   int goalAgainst;
}team;

int compare_function(const void *a,const void *b){
         
      team *x = (team *) a;
      team *y = (team *) b;
     
         
      if( x->point != y->point ){
         //printf("For points between %s and %s\n",x->name,y->name);
         return y->point - x->point;
      }
      else if (x->numWin != y->numWin){
         //printf("For wins between %s and %s\n",x->name,y->name);
         return y->numWin - x->numWin;   
      }
      else if( (x->goalScored-x->goalAgainst) != (y->goalScored - y->goalAgainst) ){   
         //printf("For goalDifference between %s and %s\n",x->name,y->name);
         return (y->goalScored-y->goalAgainst) - (x->goalScored - x->goalAgainst);
      }
      else if( x->goalScored != y->goalScored){
         //printf("For goal Scored between %s and %s\n",x->name,y->name);
         return y->goalScored - x->goalScored;
      }
      else if( x->numGame != y->numGame ){
         //printf("For number of game between %s and %s\n",x->name,y->name);
         return x->numGame - y->numGame;
      }
      else{
         int i;
         char first[32],second[32];
         
        for( i = 0 ; i < strlen(x->name) ; i++ )
            first[i] = tolower(x->name[i]);   
               
            
         for( i = 0 ; i < strlen(y->name) ; i++ )
            second[i] = tolower(y->name[i]);      
         
         //printf("For lex order between %s and %s\n",x->name,y->name);
         
         return !strcmp(first,second);
      }
}

int ConvertInt(char *str){

   int i,j,len = strlen(str),k=0,sum=0;
   
   for( i = len - 1 ; i >= 0 ; i--){
      
      int temp = 1;
      
      for( j = 0 ; j < k ; j++ )
         temp *= 10;
         
      sum += temp * (str[i]-'0');
      k++;
   }   

   return sum;
}

int main(){
   
   int numTournament;         //0<N<1000
   char TournamentName[102];   // < 100 char
   int numTeam;            //1 < T <= 30 , then T lines
   int numMatch;
   team *Team;    
     int cases,count=0;
     int i,j;
     char Team1[32],Team2[32],Goal1[3],Goal2[3];
     int NumGoal1,NumGoal2;
     
     
     scanf("%d",&cases);

     
     while(count++ < cases){
     
        if(count > 1)
           printf("\n");
     
        scanf("%*c%[^\n]",TournamentName);
        scanf("%*c%d%*c",&numTeam);
        
        
        //printf("%s %d\n",TournamentName,numTeam);
        
        
        Team = new team[numTeam];
        
        for( i = 0 ; i < numTeam ; i++){
           scanf("%[^\n]%*c",Team[i].name);
           
           Team[i].point = Team[i].numGame = Team[i].numWin = Team[i].numTie = Team[i].numLoss = Team[i].goalScored =
           Team[i].goalAgainst = 0;   
        }
        
        scanf("%d",&numMatch);
        
        for( i = 0 ; i < numMatch ; i++ ){
           scanf("%*c%[^#]%*c%[0-9]%*c%[0-9]%*c%[^\n]",Team1,Goal1,Goal2,Team2);
           
           NumGoal1 = ConvertInt(Goal1);
         NumGoal2 = ConvertInt(Goal2);
           
           //printf("Team1 %s, goal %d,Team2 %s, goal %d\n",Team1,NumGoal1,Team2,NumGoal2);
         
          for( j = 0 ; j < numTeam ; j++){
         
             if(!strcmp(Team1,Team[j].name)){
                Team[j].goalScored += NumGoal1; Team[j].goalAgainst += NumGoal2; Team[j].numGame++;
                if(NumGoal1 > NumGoal2)
                   Team[j].numWin++,Team[j].point+=3;
                else if(NumGoal1 == NumGoal2)
                   Team[j].numTie++,Team[j].point+=1;
                else Team[j].numLoss++;
                
             }
             
             else if(!strcmp(Team2,Team[j].name)){
                Team[j].goalScored += NumGoal2; Team[j].goalAgainst += NumGoal1; Team[j].numGame++;
                if(NumGoal2 > NumGoal1)
                   Team[j].numWin++,Team[j].point+=3;
                else if(NumGoal1 == NumGoal2)
                   Team[j].numTie++,Team[j].point+=1;
                else Team[j].numLoss++;
                
             }
             else;
          }       
        }
        
        
        qsort(Team,numTeam,sizeof(team),compare_function);
       
       
          printf("%s\n",TournamentName);
       
          for( i = 0 ; i < numTeam ; i++)
             printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",i+1,Team[i].name,Team[i].point,Team[i].numGame,Team[i].numWin,Team   [i].numTie,Team[i].numLoss,Team[i].goalScored-Team[i].goalAgainst,Team[i].goalScored,Team[i].goalAgainst);
             
           
    
     }    
                

   return 0;
}


Please someone help to find my problem and give some critical I/O
Thanks.
assasin
New poster
 
Posts: 7
Joined: Wed Feb 13, 2008 3:59 pm
Location: Dhaka,Bangladesh

Re: 10194 - Football (aka Soccer)

Postby mohitkanwal » Sun May 31, 2009 8:53 am

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 :)
mohitkanwal
New poster
 
Posts: 7
Joined: Sun Mar 29, 2009 6:32 pm

Re: 10194 - Football (aka Soccer)

Postby aprogrammer » Wed Oct 14, 2009 6:49 pm

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);
               times.add(t);
            }
            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!
aprogrammer
New poster
 
Posts: 1
Joined: Wed Oct 14, 2009 6:42 pm

PreviousNext

Return to Volume CI

Who is online

Users browsing this forum: No registered users and 1 guest