您的位置:首页 > 其它

【luogu1012】拼数(字符串的操作+冒泡?)

2017-08-23 21:39 267 查看
题目:我是超链接

题解:

这破题怎么这么麻烦------Shallwe

因为考虑了341 34这种情况,而且字符串又不按照我想象的方法排序,必须一个一个冒泡走起啦

代码:

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int n,i,j;
char xx[100050],yy[100050];
struct word{char st[100050];}ww[22];
int cmp(word a,word b){return strcmp(a.st,b.st)>0;}
int main()
{
scanf("%d",&n);
for (i=1;i<=n;i++) scanf("%s",&ww[i].st);
sort(ww+1,ww+n+1,cmp);
bool bo=false;
i=1;
while (!bo)
{
bo=true;
for (j=1;j<=n-i;j++)
{
memset(xx,0,sizeof(xx));
memset(yy,0,sizeof(yy));
strcat(xx,ww[j].st);
strcat(xx,ww[j+1].st);
strcat(yy,ww[j+1].st);
strcat(yy,ww[j].st);
if (strcmp(xx,yy)<0) swap(ww[j+1],ww[j]);
bo=false;
}
i++;
}
for (i=1;i<=n;i++) printf("%s",ww[i].st);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: