POJ 3617 Best Cow Line

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<stack>
#include<queue>
using namespace std;

char s[4000];
int N;

int main()
{
    while(scanf("%d",&N)!=EOF)
    {
        for(int i=0;i<N;i++)
        {
            scanf("\n%c",&s[i]);
        }
       int start=0,end=N-1;
       int count=0;
        while(start<=end)
        {
            bool left = false;
            for(int i = 0; start + i<=end;i++)
            {
                if(s[start+i]<s[end-i])
                {
                    left=true;
                    break;
                }
                else if(s[start+i]>s[end-i])
                {
                    left=false;
                    break;
                }
            }
            if(!left)
            {
                printf("%c",s[end]);
                end--;
            }
            else
            {
                printf("%c",s[start]);
                start++;
            }
            count++;
            if(count==80){
                putchar('\n');
                count=0;
            }
        }
        putchar('\n');
    }
	return 0;
}

你可能感兴趣的:(POJ 3617 Best Cow Line)