文章

8

粉丝

0

获赞

18

访问

4.1k

头像
整数排序 题解:
P1905 华东师范大学2022年机试
发布于2025年3月16日 18:37
阅读数 304

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;

struct node
{
    int bit;
    int num;
};

bool com(const node &a, const node &b)
{
    if (a.bit == b.bit)
        return a.num < b.num;
    return a.bit > b.bit;
}

int main()
{

    vector<node> p;
    int n;

    // 逐个读取整数
    while (scanf("%d",&n) != EOF)
    {
        int bit = 0;
        int temp = n;
        while (temp)
        {
            bit++;
            temp /= 10;
        }
        p.push_back({bit, n});
    }

    // 排序
    sort(p.b...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发