标签:src 编程 mic 数字 lock loading static 银行 for
题目描述
输入第一行为n代表接下来有每行有几个数,下边有两行输入
每行都有n个数字。如下:
输入
6
67 88 91 88 99 88
80 92 69 70 85 77
输出:
99, 85
91, 69
88, 92
88, 77
88, 70
67, 80
排序规则:按照第一行的那6个数字对其进行排序,如果第一行中出现了两个数相同的情况,就按照下边第二行中大的数排序
输入输出描述:
见上述
Java代码
package ncompanydemos.p3_minsheng;
import java.util.Arrays;
import java.util.Scanner;
/**
* @author jiyongjia
* @create 2020/7/12 - 19:06
* @descp:
*/
public class Exam01 {
//自测
public static void main(String[] args) {
int[][] ints = {{67, 80}, {88, 92}, {91, 69}, {88, 70}, {99, 85}, {88, 77}};
int[][] solve = solve(ints);
for (int[] s:solve){
System.out.println(Arrays.toString(s));
}
}
//牛客输入输出
public static void main1(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[][] ints = new int[n][2];
for (int i = 0; i < n; i++) {
ints[i][0] = scanner.nextInt();
}
for (int i = 0; i < n; i++) {
ints[i][1] = scanner.nextInt();
}
//调用方法
int[][] solve = solve(ints);
for (int[] s:solve){
System.out.println(s[0]+" "+s[1]);
}
}
public static int[][] solve(int[][] arr){
for (int i=0;i<arr.length-1;i++){
for (int j = 0; j < arr.length-1-i; j++) {
int[] temp;
if(arr[j][0]<arr[j+1][0]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}else if((arr[j][0]==arr[j+1][0]) && (arr[j][1]<arr[j+1][1])){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}else{
continue;
}
}
}
return arr;
}
}
输出
标签:src 编程 mic 数字 lock loading static 银行 for
原文地址:https://www.cnblogs.com/jiyongjia/p/13292504.html