Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class League
- {
- public static void ListMatches(List TeamList)
- {
- int num_of_teams = 12;
- int num_of_days = num_of_teams-1;
- int half_size_of_team = num_of_teams/2;
- List teams = new ArrayList();
- List matches = new ArrayList();
- List derbymatches = new ArrayList();
- teams.addAll(TeamList);
- teams.remove(0);
- int teamSize = teams.size();
- for(int day = 0; day < num_of_days; day++)
- {
- System.out.println("Day {0} " + (day + 1));
- int teamIdx = day % teamSize;
- //for the first team in each day, match it with team 1
- matches.add(teams.get(teamIdx)+"/"+TeamList.get(0));
- for(int i=1; i < half_size_of_team; i++)
- {
- int firstTeam = (day + 1) % teamSize;
- int secondTeam = (day + teamSize - i) % teamSize;
- matches.add(teams.get(firstTeam)+"/"+teams.get(secondTeam));
- }
- }
- for(int i =0; i<matches.size(); i++)
- {
- String temp = matches.get(i).toString();
- if(isLastMatchDerby(temp) && isMatchDerby(temp))
- {
- System.out.println("This match " + temp + "is a derby");
- derbymatches.add(temp);
- continue;
- }
- else
- {
- System.out.println(temp);
- }
- }
- if(derbymatches.size() > 0)
- {
- System.out.println("I still have items left...");
- for(int i = 0; i<derbymatches.size(); i++)
- {
- String temp = derbymatches.get(i).toString();
- System.out.println(temp);
- }
- }
- }
- public static void main(String[] args)
- {
- List TeamList = new ArrayList();
- TeamList.add("Team A");TeamList.add("Team B");TeamList.add("Team C");TeamList.add("Team D");
- TeamList.add("Team E");TeamList.add("Team F");TeamList.add("Team G");TeamList.add("Team H");
- TeamList.add("Team I");TeamList.add("Team K");TeamList.add("Team L");TeamList.add("Team M");
- ListMatches(TeamList);
- }
- public static boolean isLastMatchDerby(String par)
- {
- String pars[] = par.split("/");
- String a = pars[0];
- String b = pars[1];
- if(a == "Team A" && b == "Team G")
- return true;
- if(a == "Team G" && b == "Team A")
- return true;
- if(a == "Team C" && b == "Team D")
- return true;
- if(a == "Team D" && b == "Team C")
- return true;
- if(a == "Team C" && b == "Team E")
- return true;
- if(a == "Team E" && b == "Team C")
- return true;
- if(a == "Team D" && b == "Team E")
- return true;
- if(a == "Team E" && b == "Team D")
- return true;
- return false;
- }
- public static boolean isMatchDerby(String par)
- {
- String pars[] = par.split("/");
- String a = pars[0];
- String b = pars[1];
- if(a == "Team A" && b == "Team G")
- return true;
- if(a == "Team G" && b == "Team A")
- return true;
- if(a == "Team C" && b == "Team D")
- return true;
- if(a == "Team D" && b == "Team C")
- return true;
- if(a == "Team C" && b == "Team E")
- return true;
- if(a == "Team E" && b == "Team C")
- return true;
- if(a == "Team D" && b == "Team E")
- return true;
- if(a == "Team E" && b == "Team D")
- return true;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment