Problem | Result | Memory | Time | Language | Code Length |
3617 | Accepted | 724K | 32MS | G++ | 567B |
#include <iostream>
using namespace std;
//《挑战程序设计竞赛》例题
int main()
{
int NUM;
cin>>NUM;
int a=0;
int b=NUM-1;
char da[NUM];
for(int i=0;i<NUM;i++)
{
cin>>da[i];
}
int count=0;
while(a<=b)
{
int flag=0;
for(int i=0;i<(b-a+1);i++)
{
if(da[a+i]<da[b-i])
{
count++;
cout<<da[a];
a=a+1;
flag=1;
break;
}else if(da[a+i]>da[b-i])
{
count++;
cout<<da[b];
b=b-1;
flag=1;
break;
}
}
if(flag==0)
{
count++;
cout<<da[a];
a=a+1;
}
if(count%80==0)
{
cout<<endl;
}
}
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/4fdf0b847b1f9f7d72468a62f816e272.png)
![](https://i-blog.csdnimg.cn/blog_migrate/90725fbef0be07caecee74d7c35b26ae.png)
已知字符串S和空串T,可进行 删除S的第一个字符加入T的尾部;删除S的最后一个字符加入T尾部;两种操作。求字典序最小的字符串T。