Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Solution {
- public static boolean less(int year1, int height1, int year2, int height2) {
- if (year1>year2) return true;
- if (year1<year2) return false;
- if (height1<height2) return true;
- return false;
- }
- public static void insertion_sortchan(int a[],int b[]) {
- int n = a.length;
- for(int i = 2; i < n; i+=2) {
- for(int j = i - 2; j >= 0; j-=2) {
- if (less(a[j + 2], b[j + 2], a[j], b[j])) {
- int tmp_a = a[j]; a[j] = a[j + 2]; a[j + 2] = tmp_a;
- int tmp_b = b[j]; b[j] = b[j + 2]; b[j + 2] = tmp_b;
- }
- }
- }
- }
- public static void insertion_sortle(int a[],int b[]) {
- int n = a.length;
- for(int i = 3; i < n; i+=2) {
- for(int j = i-2; j >= 0; j-=2) {
- if (less(a[j + 2], b[j + 2], a[j], b[j])) {
- int tmp_a = a[j]; a[j] = a[j + 2]; a[j + 2] = tmp_a;
- int tmp_b = b[j]; b[j] = b[j + 2]; b[j + 2] = tmp_b;
- }
- }
- }
- }
- public static void main(String arg[]) {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- int a[] = new int[n];
- int b[] = new int[n];
- for(int i = 0; i < n; ++i) a[i] = in.nextInt();
- for(int i = 0; i < n; ++i) b[i] = in.nextInt();
- insertion_sortchan(a, b);
- insertion_sortle(a,b);
- for(int i = 0; i < n; ++i) {
- System.out.println(a[i] + " " + b[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement