http://www.luogu.org/problem/show?pid=1781
排序即可,注意要用字符串,注意字符串的交换方法以及比较大小,n<=20用选择排序即可
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ms(i,j) memset(i, j, sizeof(i));
using namespace std;
int xh[25];
char ch[25][1005];
int cmp(char a[], char b[])
{
int lena = strlen(a);
int lenb = strlen(b);
if (lena>lenb) return true;
else if (lena<lenb) return false;
else for (int i=0;i<lena;i++)
if (a[i]>b[i]) return true;
else if (a[i]<b[i]) return false;
return true;
}
int main()
{
int n;
scanf("%d\n", &n);
for (int i=1;i<=n;i++) {scanf("%s", ch[i]); xh[i] = i;}
for (int i=1;i<n;i++)
for (int j=i+1;j<=n;j++)
{
if (cmp(ch[i], ch[j]))
{
char f[1005];
memcpy(f, ch[i], sizeof ch[i]);
memcpy(ch[i], ch[j], sizeof ch[j]);
memcpy(ch[j], f, sizeof f);
int y = xh[i];
xh[i] = xh[j];
xh[j] = y;
}
}
printf("%d\n%s\n", xh[n], ch[n]);
return 0;
}