nyoj283对称排序
来源:互联网 发布:中信建投股票交易软件 编辑:程序博客网 时间:2024/05/18 03:37
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct ch{
char s[26];
int len;
}str[1000];
bool cmp(struct ch a,struct ch b)
{
return a.len < b.len;
}
int main()
{
int m;
int k = 1;
while(scanf("%d",&m) && m != 0)
{
getchar();
int i;
for(i = 0;i < m;i++)
{
gets(str[i].s);
str[i].len = strlen(str[i].s);
}
sort(str,str+m,cmp);
printf("SET %d\n",k++);
for(i = 0;i < m;i+=2)
{
puts(str[i].s);
}
if(m%2) i = m-2;
else i = m-1;
for(i ;i > 0;i-=2)
{
puts(str[i].s);
}
}
return 0;
#include<string.h>
#include<algorithm>
using namespace std;
struct ch{
char s[26];
int len;
}str[1000];
bool cmp(struct ch a,struct ch b)
{
return a.len < b.len;
}
int main()
{
int m;
int k = 1;
while(scanf("%d",&m) && m != 0)
{
getchar();
int i;
for(i = 0;i < m;i++)
{
gets(str[i].s);
str[i].len = strlen(str[i].s);
}
sort(str,str+m,cmp);
printf("SET %d\n",k++);
for(i = 0;i < m;i+=2)
{
puts(str[i].s);
}
if(m%2) i = m-2;
else i = m-1;
for(i ;i > 0;i-=2)
{
puts(str[i].s);
}
}
return 0;
}
以下是最优代码:
#include<stdio.h>
#include<string.h>
main()
{
int x,i,j,q=0;
char s[16][26],t[26],z[16][26];
while(1)
{
scanf("%d",&x);
if(x==0) break;
q++;
getchar();
for(i=0;i<x;i++)
gets(s[i]);
for(i=1;i<x;i++)
for(j=0;j<x-i;j++)
if(strlen(s[j])>strlen(s[j+1]))
{strcpy(t,s[j]);strcpy(s[j],s[j+1]);strcpy(s[j+1],t);}
for(i=0,j=0;i<x;i++,j++)
{ strcpy(z[j],s[i]);
if(i!=x-1) strcpy(z[x-j-1],s[++i]);
}
printf("SET %d\n",q);
for(i=0;i<x;i++)
puts(z[i]);
}
}
要存储多个字符串的时候,法一:二维数组;法二:结构体
0 0
- NYOJ283 对称排序
- nyoj283对称排序
- NYoj283对称排序
- nyoj283对称排序
- 对称排序
- 对称排序
- 对称排序
- 对称排序
- 对称排序
- 对称排序
- 对称排序
- 对称排序
- 题目:283 对称排序
- NYOJ - 对称排序
- nyoj,283,对称排序
- nyoj-283-对称排序
- NYOJ-283 对称排序
- NYOJ 283 对称排序
- Android Activity生命周期整理
- flex调用webservice绑定DataGrid
- C++数据结构栈的实现
- Silverlight+wcf程序
- 哈希表入门
- nyoj283对称排序
- iOS开发的一些奇巧淫技 包括一款GIF框架
- c#编程之UDP通信
- 微信公众平台开发接口PHP SDK完整版
- USACO 3.1.1
- Android项目中引用外部项目library失败的原因
- 安卓手机用WIFI与电脑共享文件
- Qt 实例--计算圆面积
- [Leetcode]174. Dungeon Game @python