不会做,完全没思路,不知道要用什么比较方法来判断谁放在哪个位置合适,看了题解发现用类似冒泡的方法+string可以比较!tql.
#include <cstdio>
#include <cstring>
using namespace std;
char a[21][1000];
bool cmp(char x[],char y[])
{
char a1[1000],a2[1000];
strcpy(a1,x);
strcpy(a2,y);
strcat(a1,y);
strcat(a2,x);
if(strcmp(a1,a2) >= 0) return true;
else return false;
}
void swap(int i,int j)
{
char temp[1000];
strcpy(temp,a[i]);
strcpy(a[i],a[j]);
strcpy(a[j],temp);
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%s",a[i]);
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
{
if(cmp(a[i],a[j])==false) swap(i,j);
}
for(int i=0;i<n;i++) printf("%s",a[i]);
return 0;
}
博客介绍了如何解决编号为P1012的编程问题,作者分享了自己在解题过程中遇到的困难,即如何确定数字的合适位置。通过查看题解,作者了解到可以运用类似于冒泡排序的算法结合字符串比较方法来解决这个问题,对此表示赞叹。
136

被折叠的 条评论
为什么被折叠?



