文章

246

粉丝

0

获赞

1184

访问

99.6k

头像
整数排序 题解:
P1905 华东师范大学2022年机试
发布于2026年3月19日 17:10
阅读数 341

#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

vector<int> nums;

bool cmp(int a,int b)
{
    int len1=0,len2=0;
    int x=abs(a),y=abs(b);
    while(x)
    {
        len1++;
        x/=10;
    }
    while(y)
    {
        len2++;
        y/=10;
    }
    if(len1!=len2)
    return len1>len2;
    return a<b;
}

int main()
{
    int x;
    while(cin>>x)
    nums.push_back(x);
    sort(nums.begin(),nums.end(),cmp);
    for(auto p:nums)
    cout<<p<<" ";
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发