H2230823078


私信TA

用户名:dotcpp0618148

访问量:930

签 名:

https://devcpp.gitee.io/

等  级
排  名 1109
经  验 3079
参赛次数 0
文章发表 9
年  龄 0
在职情况 学生
学  校 贺州学院
专  业

  自我简介:

https://royqh1979.gitee.io/redpandacpp/

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, m;

struct node {
	int v, cnt = 0;
} a[N];

bool cmp(node a, node b) {

	if (a.cnt != b.cnt) 
		return a.cnt < b.cnt;
	
	else
		return a.v < b.v;
}

int main() {

	cin >> n >> m;

	for (int i = 1; i <= n; i++) {
		a[i].v = i;
		int j = i;
		while (j != 0) {
			a[i].cnt += (j % 10);
			j /= 10;
		}
	}

	sort(a, a + 1 + n, cmp);

//	for (int i = 1; i <= n; i++)
//		cout << a[i].v << " ";
	cout<<a[m].v<<endl;
}

解题思路:

注意事项:

参考代码:

 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区