第一题
package ccf201503; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class p1f { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String head = bf.readLine(); String[] temp = head.split(" "); int n = Integer.parseInt(temp[0]); int m = Integer.parseInt(temp[1]); int[][] newXY = new int[m][n]; for (int i = 0; i < n; i++) { temp = bf.readLine().split(" "); for (int j = 0; j < m; j++) { newXY[m - 1 - j][i] = Integer.parseInt(temp[j]); } } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { System.out.print(newXY[i][j]+" "); } System.out.println(); } } }
第二题
package ccf201503; import java.util.Scanner; public class p2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] num = new int[n]; int[] count = new int[1001]; int len = 0; for (int i = 0; i < n; i++) { boolean flag = false; num[i] = sc.nextInt(); for (int j = 0; j < i; j++) { if (num[j] == num[i]) { flag = true; } } if (flag) { count[num[i]]++; } else { count[num[i]] = 1; len++; } } int[][] res = new int[len][2]; int index = 0; for (int i = 0; i < 1001; i++) { if (count[i] != 0) { res[index][0] = i; res[index][1] = count[i]; index++; } } res = getNewRes(res); for (int i = 0; i < len; i++) { for (int j = 0; j < 2; j++) { System.out.print(res[i][j] + " "); } System.out.println(); } } public static int[][] getNewRes(int[][] res) { int len = res.length; for (int i = 0; i < len; i++) { for (int j = 1; j < len - i; j++) { if (res[j-1][1] < res[j][1]) { int t0 = res[j-1][0]; res[j-1][0] = res[j][0]; res[j][0] = t0; int t1 = res[j-1][1]; res[j-1][1] = res[j][1]; res[j][1] = t1; } } } return res; } }