文章
13
粉丝
120
获赞
1
访问
6.8k
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int count(int n)
{
int count = 0;
while (n != 0)
{
count++;
n /= 10;
}
return count;
}
bool compare(int a, int b)
{
int counta = count(a), countb = count(b);
return counta == countb ? a < b : counta > countb;
}
int main()
{
string line, tmp;
getline(cin, line);
vector<int> nums;
for (stringstream str1(line); str1 >> tmp;)
nums.push_back(stoi(tmp));
sort(nums.begin(), nums.end(), compare);
int len = nums.size();
for (int i = 0; i < len; i++)
cout << nums[i] << " ";
cout << endl;
}
登录后发布评论
暂无评论,来抢沙发