欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

POJ 3617 Best Cow Line

程序员文章站 2022-07-04 20:11:01
...

POJ 3617 Best Cow Line

POJ 3617 Best Cow LinePOJ 3617 Best Cow LinePOJ 3617 Best Cow Line

  • Source Code
    #include<iostream>
    using namespace std;
    int main()
    {
    	int n;
    	while (cin >> n)
    	{
    		char a[2005];
    		for (int i = 0; i < n; i++)
    			cin >> a[i];
    		int st = 0, back = n - 1; int t = 0;
    		while (st <= back)
    		{
    			bool b = 0;
    			for (int i = 0; st + i < back; i++)
    			{
    				if (a[st + i] > a[back - i])
    				{
    					b = 1; break;
    				}
    				else if (a[st + i] < a[back - i])
    					break;
    			}
    			if ((t % 80 == 0)&&t!=0) cout << endl;
    			t++;
    			if (b == 1) cout << a[back--];
    			else cout << a[st++];
    		}
    		cout << endl;
    	}
    	return 0;
    }