๐
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import cmp_to_key | |
arr = [1, 2, 3, 4, 5] | |
def my_cmp(a, b): | |
if a == b: | |
return 0 | |
elif a < b: | |
return -1 | |
else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import cmp_to_key | |
def my_cmp(a, b): | |
if a[1] != b[1]: | |
return a[1] - b[1] | |
return a[0] - b[0] | |
n = int(input()) | |
arr = [list(map(int, input().split())) for _ in range(n)] | |
arr.sort(key=cmp_to_key(my_cmp)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import cmp_to_key | |
def my_cmp(a, b): | |
if a[1] != b[1]: | |
return a[1] - b[1] | |
return a[0] - b[0] | |
n = int(input()) | |
arr = [list(map(int, input().split())) for _ in range(n)] | |
arr.sort(key=cmp_to_key(my_cmp)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void solve() { | |
int n; | |
cin >> n; | |
vector<pair<int, int>> arr(n); | |
for (int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr.sort(Comparator.reverseOrder()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr.sort(reverse=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sort(arr.begin(), arr.end(), greater<>()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | |
int n = Integer.parseInt(br.readLine()); | |
ArrayList<Integer> arr = new ArrayList<>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.Arrays; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | |
int n = Integer.parseInt(br.readLine()); | |
int[] arr = new int[n]; | |
for(int i = 0; i < n; i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
arr = [int(input()) for _ in range(n)] | |
arr.sort() | |
for k in arr: | |
print(k) |