Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Test
- {
- public static void main(String args[])
- {
- Scanner in = new Scanner(System.in);
- int Tournaments = Integer.parseInt(in.nextLine());
- while(Tournaments > 0)
- {
- Tournaments--;
- String TournamentName = in.nextLine();
- int TeamsCount = Integer.parseInt(in.nextLine());
- ArrayList<Team> Teams = new ArrayList<Team>(TeamsCount);
- for(int i = 0 ;i < TeamsCount;i++)
- {
- String TeamName = in.nextLine();
- Teams.AddLast(new Team(TeamName));
- }
- int MatchCount = Integer.parseInt(in.nextLine());
- while(MatchCount > 0)
- {
- MatchCount--;
- String Won = "";
- String Lost = "";
- int WonGoals = 0;
- int LostGoals = 0;
- int Count = 0;
- String t = in.nextLine();
- for(int i = 0;i<t.length();i++)
- {
- //Suppose that first time won then swap if it's not
- if(Character.isDigit(t.charAt(i)))
- {
- if(Count == 1)
- WonGoals = WonGoals * 10 + Character.getNumericValue(t.charAt(i));
- else
- LostGoals = LostGoals * 10 + Character.getNumericValue(t.charAt(i));
- }
- else if(Character.isLetter(t.charAt(i)))
- {
- if(Count == 0)
- Won += t.charAt(i);
- else
- Lost += t.charAt(i);
- }
- else
- {
- /*
- if count is 0 : still getting first team
- if count is 1: still getting first team goals
- if count is 2: still getting second team name
- if count is 3: still getting second team goals
- */
- Count++;
- }
- }
- if(WonGoals < LostGoals)//swap if our suppose is wrong
- {
- int temp = WonGoals;
- WonGoals = LostGoals;
- LostGoals = temp;
- String w = Won;
- Won = Lost;
- Lost = w;
- }
- for(int j = 0 ;j < TeamsCount;j++)
- {
- if (Teams.Get(j).Name.equals(Won))
- {
- Teams.Get(j).Add(WonGoals,LostGoals);
- }
- else if(Teams.Get(j).Name.equals(Lost))
- {
- Teams.Get(j).Add(LostGoals,WonGoals);
- }
- }
- }
- Teams.Sort();
- System.out.println(TournamentName);
- for(int i = 0;i<TeamsCount;i++)
- {
- int j = i + 1;
- int ties = Teams.Get(i).GamesCount - Teams.Get(i).Wins - Teams.Get(i).Loses;
- System.out.println(j + ") " + Teams.Get(i).Name + " " + Teams.Get(i).Points + "p, "
- + Teams.Get(i).GamesCount + "g (" + Teams.Get(i).Wins + "-" + ties + "-" + Teams.Get(i).Loses
- + "), " + Teams.Get(i).GoalDifference + "gd (" + Teams.Get(i).GoalsScored + "-"
- + Teams.Get(i).GoalsAgainst + ")"
- );
- }
- }
- }
- }
- interface List <T extends Comparable<T>>
- {
- public Boolean IsEmpty();//return true if the List is empty
- public void Add(int i,T e);//add element e at index i
- public void AddFirst(T e);//add e to the beginning of the list
- public void AddLast(T e);//add e to the end of the list
- public void Delete(T e);//Delete e from the list if it exists
- public void Delete(int i);//Delete element at index i
- public void DeleteFirst();//Delete the first element
- public void DeleteLast();//Delete the last element
- public void Set(int i,T e);//Set the element at index i to e
- public T Get(int i);//return the value of element at index i
- }
- class ArrayList<T extends Comparable<T>> implements List<T>
- {
- static int MaxSize = 1003;//some random maximum size for our array lists
- public int Size = 0;
- public int Capacity = 0;
- T[] MyList;
- public ArrayList()//Default Constructor
- {
- this(MaxSize);
- }
- public ArrayList(int Capacity)
- {
- MyList = (T[]) new Comparable[Capacity]; // safe casting
- }
- public Boolean IsEmpty()//returns true if the List is empty
- {
- return Size == 0;
- }
- public void Add (int i,T e)throws IndexOutOfBoundsException //add element e at index i
- {
- for(int j = Size;j>i;j--)
- MyList[j] = MyList[j-1];
- MyList[i] = e;
- Size++;
- }
- public void AddFirst(T e)//add e to the beginning of the list
- {
- MyList[0] = e;
- if(IsEmpty()) Size++;
- }
- public void AddLast(T e)//add e to the end of the list
- {
- MyList[Size] = e;
- Size++;
- }
- public void Delete(T e)//Delete e from the list if it exists
- {
- for(int i = 0 ; i < Size;i++)
- if(MyList[i] == e)
- Delete(i);
- }
- public void Delete(int i)throws IndexOutOfBoundsException//Delete element at index i
- {
- for(int j = i + 1 ;j < Size;j++)
- MyList[j - 1] = MyList[j];
- Size--;
- }
- public void DeleteFirst()throws IndexOutOfBoundsException//Delete the first element
- {
- Delete(0);
- }
- public void DeleteLast()throws IndexOutOfBoundsException//Delete the last element
- {
- Delete(Size - 1);
- }
- public void Set(int i,T e)throws IndexOutOfBoundsException//Set the element at index i to e
- {
- MyList[i] = e;
- }
- public T Get(int i)throws IndexOutOfBoundsException//return the value of element at index i
- {
- return MyList[i];
- }
- public void Sort()
- {
- int smallest;
- for(int i = 0;i<Size;i++)
- {
- smallest = i;
- for(int j= i+1;j<Size;j++)
- {
- if(MyList[j].compareTo(MyList[smallest])>0)//Compare geneitc types
- {
- smallest = j;
- }
- }
- T temp = MyList[i];
- MyList[i] = MyList[smallest];
- MyList[smallest] = temp;
- }
- }
- }
- class Team implements Comparable<Team>
- {
- public String Name;
- public int Points;
- public int GamesCount;
- public int Wins;
- public int Loses;
- public int GoalDifference;//Goals Scored - Goals Against
- public int GoalsScored;
- public int GoalsAgainst;
- public Team(String s)
- {
- Name = s;
- Points = 0;
- GamesCount = 0;
- Wins = Loses = 0;
- GoalDifference = GoalsAgainst = GoalsScored = 0;
- }
- /*
- more than 0 if this > T
- less than 0 if this < T
- zero if this == T
- */
- public void Add(int Goals,int GoalsVs)
- {
- GamesCount++;
- GoalsScored+=Goals;
- GoalsAgainst+=GoalsVs;
- if(GoalsVs < Goals)//Won
- {
- Points += 3;
- Wins++;
- }
- else if(GoalsVs > Goals)//Lost
- {
- Loses++;
- }
- else
- {
- Points++;
- }
- GoalDifference = GoalsScored - GoalsAgainst;
- }
- public int compareTo(Team T)
- {
- if(this.Points != T.Points)//Compare by points first
- return this.Points - T.Points;
- if(this.Wins != T.Wins)
- return this.Wins - T.Wins;
- if(this.GoalDifference != T.GoalDifference)
- return this.GoalDifference - T.GoalDifference;
- return this.Name.toLowerCase().compareTo(T.Name.toLowerCase());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement