水题一道。。没啥好说的,比较首尾,输出小的,如果相同就往内部枚举再比较,直到不同
#include<cstdio>
#include<deque>
using namespace std;
namespace
{
deque<char> Q;
int N;
void solve()
{
int i = 0;
while (!Q.empty())
{
int l = 0, r = Q.size() - 1;
while (Q[l] == Q[r] && l < r)
{
l++;
r--;
}
if (Q[l] < Q[r])
{
putchar(Q.front());
Q.pop_front();
}
else
{
putchar(Q.back());
Q.pop_back();
}
i++;
if (i % 80 == 0)
putchar('\n');
}
}
}
int main()
{
char temp[2];
while (scanf("%d", &N) != EOF)
{
Q.clear();
while (N--)
{
scanf("%s", temp);
Q.push_back(temp[0]);
}
solve();
}
return 0;
}