
public class RoundRobinScheduler {
	
	public static void roundRobinScheduler(String[] teams) {  
		int inputTeams = teams.length;
		String[] newTeams; 						
		int k = 0; 
		String dummy ="dummy";
		if (inputTeams % 2 == 0) {
			newTeams = new String[inputTeams-1];
			for (k = 0; k < inputTeams-1; k++) //new teams excludes the first team	
				newTeams[k] = teams[k+1];	        
	    } else {
	    	newTeams = new String[inputTeams];
	    	for(k = 0; k < inputTeams-1; k++)
				newTeams[k] = teams[k+1];
	    	newTeams[inputTeams-1] = dummy;  //if number of input teams is odd number, add a dummy team
	    }

		int circularSize = newTeams.length ; //teams that's in circle, excluding the first team
		int allTeams = circularSize + 1; //includes the first team
	    int totalRounds = allTeams - 1; //rounds needed to complete tournament
	    int duels = allTeams / 2; // number of competitions in each round
	    int count = 1;
	    for (int round = totalRounds-1; round >= 0; round--)  {
	        System.out.println("round " + (count++));
	        int teamIdx = round % circularSize;
	        if(!newTeams[teamIdx].equals(dummy)) //first team, that's not in circle
	        	System.out.println(teams[0] + " vs. "+ newTeams[teamIdx] );
	        for (int i = 1; i < duels; i++) { //all other teams that are in circle              
	            int firstTeam = (round + i) % circularSize; //2nd, 3rd..
	            int secondTeam = (round  + circularSize - i) % circularSize; //2nd to last, 3rd to last..
	            if ( !newTeams[firstTeam].equals(dummy) && !newTeams[secondTeam].equals(dummy)) //skip dummy
	            	System.out.println(newTeams[firstTeam] + " vs. "+ newTeams[secondTeam]);
	        }
	        System.out.println();
	    }
	}
	
	public static void main(String[] args) {
		String[] teams = {"1", "2", "3", "4", "5","6", "7", "8", "9","10"};
		roundRobinScheduler(teams);
	}
}
