hurt


私信TA

用户名:dotcpp0638769

访问量:603

签 名:

等  级
排  名 27663
经  验 501
参赛次数 0
文章发表 2
年  龄 0
在职情况 学生
学  校 北京航空航天大学
专  业

  自我简介:

解题思路:
创建结构体用number存储数值,len存储各各数位相加的结果。根据题意定义小于运算,然后可以直接使用c++内置的sort函数进行排序。
注意事项:

参考代码:

#include<bits/stdc++.h>
using namespace std;
struct node{
    int number;
    int len;
};
bool operator < (node& A, node& B)
{
    if(A.len<B.len)return true;
    else if (A.len == B.len && A.number < B.number) return true;
    else return false;
}
struct node line[1000005];
int main() {
    int i,j,m,n;
    cin >> n >> m;
    for(i=1;i<=n;i++)
    {
        line[i].number=i;
        line[i].len=0;
    }
    for(i=1;i<=n;i++)
    {
        int ink = line[i].number;
        while(ink>0)
        {
            line[i].len = line[i].len + (ink % 10);
            ink = ink / 10;
        }
    }
    sort(line+1,line+n+1);
    cout << line[m].number << endl;
    return 0;
}


 

0.0分

2 人评分

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

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

代码解释器

代码纠错

SQL生成与解释

  评论区