题目283 对称排序
2016-07-31 08:26
232 查看
已AC代码:
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; struct line { char s[30]; int l; }; bool cmp(const line a, const line b) { return a.l < b.l; } int main() { int n, cont=1; scanf("%d", &n); while(n) { line a , b ; for(int i=0; i<n; i++) { scanf("%s", a[i].s); a[i].l = strlen(a[i].s); } sort(a, a+n, cmp); printf("SET %d\n", cont); for(int i=0, j=n-1, k=0; i<=j; i++, j--) { if(i==j) { strcpy(b[i].s, a[k].s); k++; } else { strcpy(b[i].s, a[k].s); k++; strcpy(b[j].s, a[k].s); k++; } } for(int i=0; i<n; i++) printf("%s\n",b[i].s); cont++; scanf("%d", &n); } return 0; }