您的位置:首页 > 其它

题目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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  南阳理工OJ