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