题目描述
PIPI有n个整数,这些整数都非常大,请帮PIPI为这些整数排下序。
输入
输入包含多组测试用例。
对于每一组测试用例,第一行包含一个整数N。(N<=200)
接下来N行每行包含一个整数 c 。 (0<=c<=101000)
输出
对于每一组数组,输出排序后的结果。
样例输入
3
11111111111111111111111111111
22222222222222
33333333
样例输出
33333333
22222222222222
11111111111111111111111111111
#include<bits/stdc++.h>
using namespace std;
bool cmp(string a,string b)
{
if(a.length()==b.length()) ///当a和b的长度相等时,将a和b按字典序排序
return a<b;
else
return a.length()<b.length();
}
int main()
{
int n;
vector<string>vt;
string str;
while(scanf("%d",&n)!=EOF)
{
vt.clear();
for(int i=0; i<n; i++)
{
cin>>str;
vt.push_back(str);
}
sort(vt.begin(),vt.begin()+n,cmp);
for(vector<string>::iterator it=vt.begin(); it!=vt.end(); it++)
{
cout<<*it<<endl;
}
}
}