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 helloneo » Tue Nov 21, 2006 6:09 am

hi beloni..~

you might have forgot this part..
Code: Select all
Notice that should the tie-breaker be the lexographic order, it must be done case insenstive
helloneo
Guru
 
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Postby beloni » Tue Nov 21, 2006 3:00 pm

thanks, so
should I implement some function like str_insensitive_case_cmp?
"A machine can do the work of fifty ordinary men, but no machine can do the work of one extraordinary man.", Shahriar Manzoor
beloni
Learning poster
 
Posts: 66
Joined: Thu Jan 05, 2006 1:41 pm
Location: Pelotas, RS, Brazil

Postby beloni » Tue Nov 21, 2006 10:42 pm

ok, I've submitted my code with some modifications:

Code: Select all
int str_nocase_cmp( const char *a, const char *b )
{
   int i(0);
   while( a[i] && b[i] )
   {
      if( a[i] >= 'a' && a[i] <= 'z' && b[i] >= 'A' && b[i] <= 'Z' )
      {
         if( (a[i]-32) > b[i] ) return 1;
         else if( (a[i]-32) < b[i] ) return -1;
         else i++;
      }
      else if ( a[i] >= 'A' && a[i] <= 'Z' && b[i] >= 'a' && b[i] <= 'z' )
      {
         if( a[i] > (b[i]-32) ) return 1;
         else if( a[i] < (b[i]-32) ) return -1;
         else i++;
      }
      else if( a[i] > b[i] ) return 1;
      else if( a[i] < b[i] ) return -1;
      else i++;
   }
   return 0;
}


and here, the code

Code: Select all

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

#define TOUR_LEN 101
#define TEAM_LEN 31

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

using namespace std;


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

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

int str_nocase_cmp( const char *a, const char *b )
{
   int i(0);
   while( a[i] && b[i] )
   {
      if( a[i] >= 'a' && a[i] <= 'z' && b[i] >= 'A' && b[i] <= 'Z' )
      {
         if( (a[i]-32) > b[i] ) return 1;
         else if( (a[i]-32) < b[i] ) return -1;
         else i++;
      }
      else if ( a[i] >= 'A' && a[i] <= 'Z' && b[i] >= 'a' && b[i] <= 'z' )
      {
         if( a[i] > (b[i]-32) ) return 1;
         else if( a[i] < (b[i]-32) ) return -1;
         else i++;
      }
      else if( a[i] > b[i] ) return 1;
      else if( a[i] < b[i] ) return -1;
      else i++;
   }
   return 0;
}

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


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

//   cout << name[0] << " x " << name[1] << ": " << res[0] << ", " << res[1] << '\n';

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

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

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

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

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


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


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

   if(x->stat[PT] != y->stat[PT])
      return(y->stat[PT] - x->stat[PT]); // the highest point come frist

   if(x->stat[W] != y->stat[W])
     return(y->stat[W] - x->stat[W]); //highest win come frist

   if(x->stat[GD] != y->stat[GD])
     return (y->stat[GD] - x->stat[GD]); //highest stat[GD] come frist

   if(x->stat[GS] != y->stat[GS])
    return(y->stat[GS] - x->stat[GS]); //highest stat[GS] come frist

   if(x->stat[GP] != y->stat[GP])
     return(x->stat[GP] - y->stat[GP]); //less stat[GP] come frist

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

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

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

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

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

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

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

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

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


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

Postby beloni » Thu Nov 30, 2006 5:30 pm

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

10194 Acc here but WA in Programming Challenges

Postby leoisl » Tue Feb 06, 2007 6:09 am

Anyone who got Accepted in Programming challenges (http://www.programming-challenges.com) or that went through the same situation (Acc here but WA in PC) can help me?
I tested my program several times and I didn't find an error. Maybe it's because the programming-challenges judges are more severe (I read this in a post here).

Any help would be welcome and sorry if I did any english mistake :lol:
leoisl
New poster
 
Posts: 3
Joined: Mon Dec 04, 2006 8:36 am

Postby AliSaleh » Tue Aug 21, 2007 11:17 pm

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.
AliSaleh
New poster
 
Posts: 2
Joined: Fri May 25, 2007 10:08 pm
Location: Egypt

Postby WingletE » Sun Sep 16, 2007 3:07 pm

yes, it is.
User avatar
WingletE
New poster
 
Posts: 35
Joined: Sun Aug 13, 2006 1:34 pm
Location: Taipei, Taiwan

Postby WingletE » Tue Sep 18, 2007 1:40 pm

It was almost a year ago when you posted...




Your str_nocase_cmp() function regard "ab" and "abbbbbbbb" as the same thing.

And in your ascmp() function:
Code: Select all
    ...
    return strcmp(x->name,y->name);


It should be a case insensitive strcmp() like your str_nocase_cmp().
User avatar
WingletE
New poster
 
Posts: 35
Joined: Sun Aug 13, 2006 1:34 pm
Location: Taipei, Taiwan

Postby nardhar » Wed Oct 24, 2007 2:34 am

my case insensitive function is ok, but it gives me WA, is there something wrong in my code? (what i do is copy the names to another strings which are lowercase and then i use strcmp with the new strings to sort) or should i implement case insensitive function?
Code: Select all
int compara(equipo *a, equipo *b){
   //puntos
   if (a->puntos > b->puntos) return -1;
   if (a->puntos < b->puntos) return 1;
   //ganadas
   if (a->ganadas > b->ganadas) return -1;
   if (a->ganadas < b->ganadas) return 1;
   //gol diferencia
   if (a->goles_f - a->goles_c > b->goles_f - b->goles_c) return -1;
   if (a->goles_f - a->goles_c < b->goles_f - b->goles_c) return 1;
   //goles
   if (a->goles_f > b->goles_f ) return -1;
   if (a->goles_f < b->goles_f ) return 1;
   //juegos
   if (a->ganadas + a->empatadas + a->perdidas < b->ganadas + b->empatadas + b->perdidas) return -1;
   if (a->ganadas + a->empatadas + a->perdidas > b->ganadas + b->empatadas + b->perdidas) return -1;
   //nombres
   //HERE I COPY THE NAMES IN s AND t,  AND THEN COMPARE, IS IT OK?
   char s[31],t[31];
   int i;
   for (i=0;i<strlen(a->nombre);i++)
      s[i]=tolower(a->nombre[i]);
   s[i]='\0';
   for (i=0;i<strlen(b->nombre);i++)
      t[i]=tolower(b->nombre[i]);
   t[i]='\0';
   
   return (strcmp(s,t));
}

PS. sorry for my english
nardhar
New poster
 
Posts: 4
Joined: Wed Oct 10, 2007 6:09 pm

Postby nardhar » Wed Oct 24, 2007 5:08 am

lol, found a solution in the net (got AC) and the only thing different is that the member of the team struct is a "string" and not a "char array", then it just compare like this:
Code: Select all
    string s1 = t1->name;
    string s2 = t2->name;
    for (int i=0; i<s1.length(); i++)
        if (s1[i] <='Z' && s1[i] >='A')
            s1[i] = s1[i]+32;

    for (int i=0; i<s2.length(); i++)
        if (s2[i] <='Z' && s2[i] >='A')
            s2[i] = s2[i]+32;

    return s1 > s2;

guess its my function of reading the teams' names
nardhar
New poster
 
Posts: 4
Joined: Wed Oct 10, 2007 6:09 pm

Postby nardhar » Wed Oct 24, 2007 5:23 am

lol, silly mistake (wasnt in the insensitive case), anyone who sees my "compara" function would notice
nardhar
New poster
 
Posts: 4
Joined: Wed Oct 10, 2007 6:09 pm

Need help

Postby roman_10 » Mon Dec 17, 2007 3:55 pm

I've submitted for more than 10 times for this problem, anyone could help me to look at the code?
Code: Select all
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <cstdlib>
#include <algorithm>

using namespace std;

typedef struct{
   string name;
   int b;
   int c;
   int d;
   int e;
   int f;
   int g;
   int h;
   int i;
} Team;

bool cmp(Team aa, Team bb) {
   if (aa.b != bb.b)
      return aa.b > bb.b;
   if (aa.d != bb.d)
      return aa.d > bb.d;
   if (aa.g != bb.g)
      return aa.g > bb.g;
   if (aa.h != bb.h)
      return aa.h > bb.h;
   if (aa.c != bb.c)
      return aa.c < bb.c;
   string s1 = aa.name;
    string s2 = bb.name;
    for (int i=0; i<s1.length(); i++)
        if (s1[i] <='Z' && s1[i] >='A')
            s1[i] = s1[i]+32;

    for (int i=0; i<s2.length(); i++)
        if (s2[i] <='Z' && s2[i] >='A')
            s2[i] = s2[i]+32;

    //return s1 < s2;
    //cout <<s1 << " " << s2 << endl;
    return lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end());
}

int main(void) {
   int n;
   cin >> n;
   string s;
   getline(cin, s);
   while (n--) {
      string to;
      getline(cin, to);
      int t;
      cin >> t;
      getline(cin, s);
      vector<Team> team(t);
      for (int ii = 0; ii < t; ++ii) {
         getline(cin, team[ii].name);
         team[ii].b = team[ii].c = team[ii].d = team[ii].e = team[ii].f = 0;
         team[ii].g= team[ii].h = team[ii].i = 0;
      }
      int ng;
      cin >> ng;
      string tmp;
      getline(cin, tmp);
      for (int ii = 0; ii < ng; ++ii) {
         string t1, t2;
         int g1, g2;
         int f_win = -2, s_win = -2; 
         getline(cin, tmp);
         int jj = 0;
         for (; jj < tmp.size(); ++jj) {
            if (tmp[jj] != '#')
               t1 += tmp[jj];
            else break;
         }
         g1 = tmp[++jj]-'0';
         ++jj;//'@'
         g2 = tmp[++jj]-'0';
         ++jj; //'#'
         ++jj;
         for (; jj < tmp.size(); ++jj)
            t2 += tmp[jj];
         if (g1 > g2) {
            f_win = 3;
            s_win = 0;
         }
         else if (g1 == g2) {
            f_win = 1;
            s_win = 1;
         }
         else {
            f_win = 0;
            s_win = 3;
         }
         //cout << t1 << " " << g1 << " " << t2 << " " << g2 << endl;
         for (int kk = 0; kk < team.size(); ++kk) {
            if (team[kk].name == t1) {
               team[kk].b += f_win;
               team[kk].c++;
               if (f_win == 3)
                  team[kk].d++;
               else if (f_win == 1)
                  team[kk].e++;
               else
                  team[kk].f++;
               team[kk].g += (g1-g2);
               team[kk].h += g1;
               team[kk].i += g2;
            } else if (team[kk].name == t2) {
               team[kk].b += s_win;
               team[kk].c++;
               if (s_win == 3)
                  team[kk].d++;
               else if (s_win == 1)
                  team[kk].e++;
               else
                  team[kk].f++;
               team[kk].g += (g2-g1);
               team[kk].h += g2;
               team[kk].i += g1;
            }
         }
      }
      sort(team.begin(), team.end(), cmp);
      cout << to << endl;
      for (int ii = 0; ii < team.size(); ++ii)
         printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n",ii+1,team[ii].name.c_str(),team[ii].b,team[ii].c,team[ii].d,team[ii].e,team[ii].f,team[ii].g,team[ii].h,team[ii].i);

      if(n)
         cout << endl;
   }
}
roman_10
New poster
 
Posts: 2
Joined: Wed Dec 05, 2007 10:04 am

Postby animenologist » Sun Feb 03, 2008 9:17 pm

Can someone please tell me whats wrong with my code? I've tried plenty of cases including going through and making sure that each comparison works. And yes, when placing them in lexicographical order, I made sure to ignore cases and putting them in case sensitive order. But no matter what, I keep getting WA. Probably the only thing I didn't try would be changing the name cases in actual matches.

Like say
2
Brazil
Norway
1
bRaZil#2@1#NoRwAy

but I'm not sure that's a valid case. Anyone have any test data I can compare to, because I just don't get what is wrong.

Code: Select all
import java.io.*;
import java.util.*;

public class Main implements Comparable<Main>{
   
   public String name;
   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.name.compareToIgnoreCase(x.name);
   }
   
   public static void main(String[] args)throws Exception{
      
      Scanner In = new Scanner(new File("football.in"));
      TreeMap<String, Integer> mapping;
      int numGames = Integer.parseInt(In.nextLine());
      
      for(int currGame = 1;currGame <= numGames;currGame++){
         if(currGame!=1)
            System.out.println();
         System.out.println(In.nextLine().trim());
         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().trim();
            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().trim();
            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);
         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+")");
         }
      }
   }
}
animenologist
New poster
 
Posts: 7
Joined: Tue Jan 22, 2008 5:55 am

Postby animenologist » Mon Feb 04, 2008 1:49 am

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.

Code: Select all
INPUT

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

OUTPUT

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)

animenologist
New poster
 
Posts: 7
Joined: Tue Jan 22, 2008 5:55 am

Postby yiuyuho » Tue Feb 05, 2008 3:29 am

Here's a few suggestions:

(1) I am not sure why you're reading from football.in? I used C++ and it should read from standard in. May be it's different for java? Or are you just been training too much? :P

(2) Don't trim the team names, as spaces are allowed, "a--" and "a---" are actually different teams, where "-" represents a space. For the same reason, don't trim a game line. But my guess is this is not the reason it is failing.

(3) The case insensitive sort can be a problem too. Sure, using java's case insensitive compare looks perfect, but in the old days of 10194 (that's like 5-6 years ago), people like to change everything to upper case when comparing, so it will mis-compare '[' (ASCII 91) with 'a' (ASCII 97), since the program changed the 'a' to 'A' (ASCII 65). Of course, just changing everything to uppercase is really an incorrect approach and I suspect java is using the correct approach. In other words, the judging solution may be using the theoretically wrong approach. This is something you can try messing with.
yiuyuho
A great helper
 
Posts: 325
Joined: Thu Feb 21, 2002 2:00 am
Location: United States

PreviousNext

Return to Volume CI

Who is online

Users browsing this forum: No registered users and 1 guest