标签:
Time Limit: 20 Sec
Memory Limit: 256 MB
http://uoj.ac/problem/9
Input
Output
共n行,每行一个字符串,表示排序的结果。
Sample Input
8
dajiahaowoshiyangli9.in
dajiahaowoshiyangli5.in
dajiahaowoshiyangli2.in
dajiahaowoshiyangli1.in
dajiahaowoshiyangli3.in
dajiahaowoshiyangli7.in
dajiahaowoshiyangli6.in
dajiahaowoshiyangli8.in
Sample Output
dajiahaowoshiyangli1.in
dajiahaowoshiyangli2.in
dajiahaowoshiyangli3.in
dajiahaowoshiyangli5.in
dajiahaowoshiyangli6.in
dajiahaowoshiyangli7.in
dajiahaowoshiyangli8.in
dajiahaowoshiyangli9.in
n≤10000
题意
题解:
直接排序就好了
先对比长度,长度相同再对比字符串就好了
代码:
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 1000010 #define mod 1000000007 #define eps 1e-6 const int inf=0x3f3f3f3f; const ll infll = 0x3f3f3f3f3f3f3f3fLL; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } //************************************************************************************** pair<int,string> s[10001]; int main() { //test; int n=read(); for(int i=0;i<n;i++) { cin>>s[i].second; s[i].first=s[i].second.size(); } sort(s,s+n); for(int i=0;i<n;i++) cout<<s[i].second<<endl; return 0; }
标签:
原文地址:http://www.cnblogs.com/qscqesze/p/4585367.html