Poj3617best cow line

Source: Internet
Author: User

This is probably the case. Here is a string that you can perform,
Take the first or last letter of the string and place it
The end of a new string (of course, the new string is empty at the beginning ).
To remove all the letters in it. At this time, a letter and its length are
A new string with the same old string. It is now required to minimize the Lexicographic Order of the new string.

My practice is to use greed. It is smaller than the first and last letter of the old string.
Put it in the first one. When two letters are the same
The second to last letter, and so on. Until two different letters are found.
The first letter of the old string is output; otherwise, the last letter is output.

If they are all the same letters, just output whatever one is.

My code is as follows:

 

#include<cstdio>int num;char cs[2010];void init(){char tmp[2];int i;scanf("%d",&num);for(i=0;i<num;i++){scanf("%s",tmp);cs[i]=tmp[0];}}void result(){bool flag=1;int sum,l,r,i;l=sum=0;r=num-1;while(l<=r){for(i=0;l+i<r-i;i++)if(cs[l+i]<cs[r-i]){flag=1;break;}else if(cs[l+i]>cs[r-i]){flag=0;break;}if(flag){putchar(cs[l]);l++;}else{putchar(cs[r]);r--;}sum++;if(sum%80==0)printf("\n");}}int main(){init();result();}


 

Poj3617best cow line

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.