7.数位排序

发布时间:2023-12-28 15:30:57

在这里插入图片描述
题目

import java.util.Arrays;
import java.util.Scanner;
//1 2 3 4 5 6 7 8 9 10 11 12 13
//5
//1 10 2 11 3 4 13 5 6 7 8 9
//3
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		int m = sc.nextInt();
		int[][] f = new int[n][2];
		for(int i=0;i<n;i++) {
			f[i][0] = i+1;
			String x = f[i][0]+"";
			for(int j=0;j<x.length();j++)
				f[i][1]+=x.charAt(j)-'0';
//			System.out.println(f[i][0]+" "+f[i][1]);
		}
		Arrays.sort(f,(o1,o2)->o1[1]==o2[1]?o1[0]-o2[0]:o1[1]-o2[1]);
		System.out.println(f[m-1][0]);
 		sc.close();
	}
}
文章来源:https://blog.csdn.net/qq_62552630/article/details/135269140
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。