比赛 |
20120330 |
评测结果 |
WWWAWAAAAW |
题目名称 |
字符串子串 |
最终得分 |
50 |
用户昵称 |
song |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2012-03-30 19:41:34 |
显示代码纯文本
#include <cstdio>
#include <cstring>
using namespace std;
int len[100];
char word[100][30];
void swap(int a,int b)
{
int i,maxlen,temp;
temp=len[a];
len[a]=len[b];
len[b]=temp;
maxlen=(len[a]>len[b])?len[a]:len[b];
for (i=0;i<maxlen;i++)
{
temp=word[a][i];
word[a][i]=word[b][i];
word[b][i]=temp;
}
}
bool checked(int a,int b)
{
int i,minlen;
bool abigger;
minlen=(len[a]<len[b])?len[a]:len[b];
for (i=0;i<minlen;i++)
if (word[a][i]<word[b][i])
{
abigger=false;
break;
}
else if (word[a][i]>word[b][i])
{
abigger=true;
break;
}
if (i==minlen)
if (len[a]<len[b])
abigger=false;
else
abigger=true;
if (abigger)
{
swap(a,b);
return(false);
}
return(true);
}
int main()
{
freopen("substring.in","r",stdin);
freopen("substring.out","w",stdout);
int i,j,n;
scanf("%d",&n);
for (i=0;i<n;i++)
{
scanf("%s",&word[i]);
len[i]=strlen(word[i]);
for (j=i;j>0;j--)
if (checked(j-1,j))
break;
}
for (i=0;i<n;i++)
printf(word[i]);
fclose(stdin);
fclose(stdout);
return(0);
}