题目描述
大整数排序
C++ 代码
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::string;
using std::sort;
bool cmp(const string& str1,
const string& str2){
if(str1.size() == str2.size()){
// 两个数字位数一样
return str1 < str2;
}else{
return str1.size() < str2.size();
}
}
int main()
{
int N;
cin >> N;
vector<string> vec;
while(N--){
string num;
cin >> num;
vec.push_back(num);
}
sort(vec.begin(),vec.end(),cmp);
for(auto &elem : vec){
cout << elem << endl;
}
return 0;
}