Problem F: STL——字符串排序
Time Limit:
1 Sec
Memory Limit:
128 MB
Submit:
3886
Solved:
1942
Description
对N个字符串排序。
0<N<=50000。每个字符串长度不超过50000,所有字符串长度总和不超过1000000。
Input
第一行读入N。
后面N行,每行一个字符串(只包含字母)。
Output
输出共N行,按字典序从小到大输出。
Sample Input
5
bcdef
qwer
tyuiphdjf
asdfghjklzzzz
z
Sample Output
asdfghjklzzzz
bcdef
qwer
tyuiphdjf
z
HINT
用STL的string容易解决。
Append Code
#include<iostream>
#include<string>
#include<stack>
#include<cstdio>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int N,n;
vector<string>st;
string s;
cin>>N;
for(n=0;n<N;n++)
{
cin>>s;
st.push_back(s);
}
stable_sort(st.begin(),st.end());
//对给定区间所有元素进行稳定排序
vector<string>::iterator it;
for(it=st.begin();it<st.end();it++)
{
cout<<*it;
cout<<endl;
}
return 0;
}