daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Feb 16th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Test
  4. {
  5.     public static void main(String args[])
  6.     {
  7.         Scanner in = new Scanner(System.in);
  8.  
  9.         int Tournaments = Integer.parseInt(in.nextLine());
  10.         while(Tournaments > 0)
  11.         {
  12.             Tournaments--;
  13.  
  14.             String TournamentName = in.nextLine();
  15.             int TeamsCount = Integer.parseInt(in.nextLine());
  16.             ArrayList<Team> Teams = new ArrayList<Team>(TeamsCount);
  17.             for(int i = 0 ;i < TeamsCount;i++)
  18.             {
  19.                 String TeamName = in.nextLine();
  20.                 Teams.AddLast(new Team(TeamName));
  21.             }
  22.             int MatchCount = Integer.parseInt(in.nextLine());
  23.             while(MatchCount > 0)
  24.             {
  25.                 MatchCount--;
  26.                 String Won = "";
  27.                 String Lost = "";
  28.                 int WonGoals = 0;
  29.                 int LostGoals = 0;
  30.                 int Count = 0;
  31.                 String t = in.nextLine();
  32.                 for(int i = 0;i<t.length();i++)
  33.                 {
  34.                     //Suppose that first time won then swap if it's not
  35.                     if(Character.isDigit(t.charAt(i)))
  36.                     {
  37.                         if(Count == 1)
  38.                             WonGoals = WonGoals * 10 + Character.getNumericValue(t.charAt(i));
  39.                         else
  40.                             LostGoals = LostGoals * 10 + Character.getNumericValue(t.charAt(i));
  41.                     }
  42.                     else if(Character.isLetter(t.charAt(i)))
  43.                     {
  44.                         if(Count == 0)
  45.                             Won += t.charAt(i);
  46.                         else
  47.                             Lost += t.charAt(i);
  48.                     }
  49.                     else
  50.                     {
  51.                         /*
  52.                         if count is 0 : still getting first team
  53.                         if count is 1: still getting first team goals
  54.                         if count is 2: still getting second team name
  55.                         if count is 3: still getting second team goals
  56.                          */
  57.                         Count++;
  58.                     }
  59.                 }
  60.                 if(WonGoals < LostGoals)//swap if our suppose is wrong
  61.                 {
  62.                     int temp = WonGoals;
  63.                     WonGoals = LostGoals;
  64.                     LostGoals = temp;
  65.  
  66.                     String w = Won;
  67.                     Won = Lost;
  68.                     Lost = w;
  69.                 }
  70.                 for(int j = 0 ;j < TeamsCount;j++)
  71.                 {
  72.                     if (Teams.Get(j).Name.equals(Won))
  73.                     {
  74.                         Teams.Get(j).Add(WonGoals,LostGoals);
  75.                     }
  76.                     else if(Teams.Get(j).Name.equals(Lost))
  77.                     {
  78.                         Teams.Get(j).Add(LostGoals,WonGoals);
  79.                     }
  80.                 }
  81.             }
  82.             Teams.Sort();
  83.             System.out.println(TournamentName);
  84.             for(int i = 0;i<TeamsCount;i++)
  85.             {
  86.                 int j = i + 1;
  87.                 int ties = Teams.Get(i).GamesCount - Teams.Get(i).Wins - Teams.Get(i).Loses;
  88.  
  89.                 System.out.println(j + ") " + Teams.Get(i).Name + " " + Teams.Get(i).Points + "p, "
  90.                 + Teams.Get(i).GamesCount + "g (" + Teams.Get(i).Wins + "-" + ties + "-" + Teams.Get(i).Loses
  91.                 + "), " + Teams.Get(i).GoalDifference + "gd (" + Teams.Get(i).GoalsScored + "-"
  92.                 + Teams.Get(i).GoalsAgainst + ")"
  93.                 );
  94.             }
  95.         }
  96.     }
  97. }
  98. interface List <T extends Comparable<T>>
  99. {
  100.     public Boolean IsEmpty();//return true if the List is empty
  101.     public void Add(int i,T e);//add element e at index i
  102.     public void AddFirst(T e);//add e to the beginning of the list
  103.     public void AddLast(T e);//add e to the end of the list
  104.     public void Delete(T e);//Delete e from the list if it exists
  105.     public void Delete(int i);//Delete element at index i
  106.     public void DeleteFirst();//Delete the first element
  107.     public void DeleteLast();//Delete the last element
  108.     public void Set(int i,T e);//Set the element at index i to e
  109.     public T Get(int i);//return the value of element at index i
  110. }
  111. class ArrayList<T extends Comparable<T>> implements List<T>
  112. {
  113.     static int MaxSize = 1003;//some random maximum size for our array lists
  114.     public int Size = 0;
  115.     public int Capacity = 0;
  116.     T[] MyList;
  117.     public ArrayList()//Default Constructor
  118.     {
  119.         this(MaxSize);
  120.     }
  121.     public ArrayList(int Capacity)
  122.     {
  123.         MyList = (T[]) new Comparable[Capacity]; // safe casting
  124.     }
  125.     public Boolean IsEmpty()//returns true if the List is empty
  126.     {
  127.         return Size == 0;
  128.     }
  129.     public void Add (int i,T e)throws IndexOutOfBoundsException //add element e at index i
  130.     {
  131.         for(int j = Size;j>i;j--)
  132.             MyList[j] = MyList[j-1];
  133.         MyList[i] = e;
  134.         Size++;
  135.     }
  136.     public void AddFirst(T e)//add e to the beginning of the list
  137.     {
  138.         MyList[0] = e;
  139.         if(IsEmpty()) Size++;
  140.     }
  141.     public void AddLast(T e)//add e to the end of the list
  142.     {
  143.         MyList[Size] = e;
  144.         Size++;
  145.     }
  146.     public void Delete(T e)//Delete e from the list if it exists
  147.     {
  148.         for(int i = 0 ; i < Size;i++)
  149.             if(MyList[i] == e)
  150.                 Delete(i);
  151.     }
  152.     public void Delete(int i)throws IndexOutOfBoundsException//Delete element at index i
  153.     {
  154.         for(int j = i + 1 ;j < Size;j++)
  155.             MyList[j - 1] = MyList[j];
  156.         Size--;
  157.     }
  158.     public void DeleteFirst()throws IndexOutOfBoundsException//Delete the first element
  159.     {
  160.         Delete(0);
  161.     }
  162.     public void DeleteLast()throws IndexOutOfBoundsException//Delete the last element
  163.     {
  164.         Delete(Size - 1);
  165.     }
  166.     public void Set(int i,T e)throws IndexOutOfBoundsException//Set the element at index i to e
  167.     {
  168.         MyList[i] = e;
  169.     }
  170.     public T Get(int i)throws IndexOutOfBoundsException//return the value of element at index i
  171.     {
  172.         return MyList[i];
  173.     }
  174.     public void Sort()
  175.     {
  176.         int smallest;
  177.         for(int i = 0;i<Size;i++)
  178.         {
  179.             smallest = i;
  180.             for(int j= i+1;j<Size;j++)
  181.             {
  182.                 if(MyList[j].compareTo(MyList[smallest])>0)//Compare geneitc types
  183.                 {
  184.                     smallest = j;
  185.                 }
  186.             }
  187.             T temp = MyList[i];
  188.             MyList[i] = MyList[smallest];
  189.             MyList[smallest] = temp;
  190.         }
  191.     }
  192. }
  193. class Team implements Comparable<Team>
  194. {
  195.     public String Name;
  196.     public int Points;
  197.     public int GamesCount;
  198.     public int Wins;
  199.     public int Loses;
  200.     public int GoalDifference;//Goals Scored - Goals Against
  201.     public int GoalsScored;
  202.     public int GoalsAgainst;
  203.     public Team(String s)
  204.     {
  205.         Name = s;
  206.         Points = 0;
  207.         GamesCount = 0;
  208.         Wins = Loses = 0;
  209.         GoalDifference = GoalsAgainst = GoalsScored = 0;
  210.     }
  211.     /*
  212.         more than 0 if this > T
  213.         less than 0 if this < T
  214.         zero if this == T
  215.      */
  216.     public void Add(int Goals,int GoalsVs)
  217.     {
  218.         GamesCount++;
  219.         GoalsScored+=Goals;
  220.         GoalsAgainst+=GoalsVs;
  221.         if(GoalsVs < Goals)//Won
  222.         {
  223.             Points += 3;
  224.             Wins++;
  225.         }
  226.         else if(GoalsVs > Goals)//Lost
  227.         {
  228.             Loses++;
  229.         }
  230.         else
  231.         {
  232.             Points++;
  233.         }
  234.         GoalDifference = GoalsScored - GoalsAgainst;
  235.     }
  236.     public int compareTo(Team T)
  237.     {
  238.        if(this.Points != T.Points)//Compare by points first
  239.            return this.Points - T.Points;
  240.  
  241.        if(this.Wins != T.Wins)
  242.            return this.Wins - T.Wins;
  243.  
  244.        if(this.GoalDifference != T.GoalDifference)
  245.            return this.GoalDifference - T.GoalDifference;
  246.  
  247.        return this.Name.toLowerCase().compareTo(T.Name.toLowerCase());
  248.     }
  249. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top