Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Solution {
  4.  
  5. public static boolean less(int year1, int height1, int year2, int height2) {
  6. if (year1>year2) return true;
  7. if (year1<year2) return false;
  8. if (height1<height2) return true;
  9. return false;
  10. }
  11. public static void insertion_sortchan(int a[],int b[]) {
  12. int n = a.length;
  13. for(int i = 2; i < n; i+=2) {
  14. for(int j = i - 2; j >= 0; j-=2) {
  15. if (less(a[j + 2], b[j + 2], a[j], b[j])) {
  16. int tmp_a = a[j]; a[j] = a[j + 2]; a[j + 2] = tmp_a;
  17. int tmp_b = b[j]; b[j] = b[j + 2]; b[j + 2] = tmp_b;
  18. }
  19. }
  20. }
  21. }
  22. public static void insertion_sortle(int a[],int b[]) {
  23. int n = a.length;
  24. for(int i = 3; i < n; i+=2) {
  25. for(int j = i-2; j >= 0; j-=2) {
  26. if (less(a[j + 2], b[j + 2], a[j], b[j])) {
  27. int tmp_a = a[j]; a[j] = a[j + 2]; a[j + 2] = tmp_a;
  28. int tmp_b = b[j]; b[j] = b[j + 2]; b[j + 2] = tmp_b;
  29. }
  30. }
  31. }
  32. }
  33.  
  34. public static void main(String arg[]) {
  35. Scanner in = new Scanner(System.in);
  36.  
  37. int n = in.nextInt();
  38. int a[] = new int[n];
  39. int b[] = new int[n];
  40. for(int i = 0; i < n; ++i) a[i] = in.nextInt();
  41. for(int i = 0; i < n; ++i) b[i] = in.nextInt();
  42. insertion_sortchan(a, b);
  43. insertion_sortle(a,b);
  44.  
  45. for(int i = 0; i < n; ++i) {
  46. System.out.println(a[i] + " " + b[i]);
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement