java to python code conversion

Solutions on MaxInterview for java to python code conversion by the best coders in the world

showing results for - "java to python code conversion"
Ilaria
07 Nov 2016
1n <- Maxindex - 1 
2REPEAT 
3NoMoreSwaps <- TRUE 
4FOR j <- 1 TO n 
5IF MyList [j] > MyList [j + l] 
6THEN 
7ENDIF 
8END FOR 
9n <- n - 1 
10Temp .... MyList[j) 
11MyList[j] <- MyList[j + 1] 
12MyList[j + 1] .... Temp 
13NoMoreSwaps <- FALSE 
14UNTIL NoMoreSwaps TRUE
Dylan
12 Jan 2019
1import java.util.*;
2
3class Checker implements Comparator<Player>{
4
5    public int compare(Player a, Player b) {
6        // If 2 Players have the same score
7        if(a.score == b.score){
8            // Order alphabetically by name
9            if(a.name.compareTo(b.name) < 0){
10                return -1;
11            }
12            else if(a.name.compareTo(b.name) > 0){
13                return 1;
14            }
15            return 0;
16        }    
17        
18        // Otherwise, order higher score first   
19        else if(a.score > b.score){
20            return -1;
21        }
22        else if(a.score < b.score){
23            return 1;
24        }
25        
26        return 0;
27    }
28}
29
30/** Alternative Approach:
31
32    class Checker implements Comparator<Player>{
33
34        public int compare(Player a, Player b) {
35            // If 2 Players have the same score
36            if(a.score == b.score){
37                // Order alphabetically by name
38                return a.name.compareTo(b.name);
39            }    
40
41            // Otherwise, order higher score first  
42            return ((Integer) b.score).compareTo(a.score);
43        }
44    }
45
46**/
47
48class Player{
49    String name;
50    int score;
51
52    Player(String name, int score){
53        this.name = name;
54        this.score = score;
55    }
56}
57
58class Solution {
59
60    public static void main(String[] args) {
61        Scanner scan = new Scanner(System.in);
62        int n = scan.nextInt();
63
64        Player[] player = new Player[n];
65        Checker checker = new Checker();
66
67        for(int i = 0; i < n; i++){
68            player[i] = new Player(scan.next(), scan.nextInt());
69        }
70        scan.close();
71
72        Arrays.sort(player, checker);
73        for(int i = 0; i < player.length; i++){
74            System.out.printf("%s %s\n", player[i].name, player[i].score);
75        }
76    }
77}				
78