POJ 3617

 

题意:给定长度为N的字符串S,现要构造一个字符串T(起初为空串)。任意进行一下的一种操作:

1>从S的头部删除一个字符,加到T的尾部

2>从S的尾部删除一个字符,加到T的尾部

目的使T的字典序最小。每80个字母一行

注意:当首尾俩个数相同时,我们应比较里面的俩个次首和次尾

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <cctype>
 5 #include <cmath>
 6 #include <time.h>
 7 #include <string>
 8 #include <map>
 9 #include <stack>
10 #include <set>
11 #include <queue>
12 #include <vector>
13 #include <algorithm>
14 #include <iostream>
15 using namespace std;
16 typedef long long ll;
17 typedef pair<int,int> P;
18 #define PI acos( -1.0 )
19 const double E = 1e-8;
20 
21 const int NO = 2000 + 5;
22 char ch[NO];
23 int n;
24 
25 void Solve()
26 {
27     int x = 0, y = n - 1;
28     int t = 0;
29     while( x <= y )
30     {
31         bool flag = false;
32         for( int i = 0; i < n; ++i )
33             if( ch[x+i] > ch[y-i] ) {
34                 flag = false;
35                 break;
36             }
37             else if( ch[x+i] < ch[y-i] ) {
38                 flag = true;
39                 break;
40             }
41         ++t;
42         if( flag ) putchar( ch[x++] );
43         else putchar( ch[y--] );
44         if( t % 80 == 0 )
45             putchar( '\n' );
46     }
47     if( t % 80 )
48         puts( "" );
49 }
50 
51 int main()
52 {
53     scanf( "%d", &n );
54     for( int i = 0; i < n; ++i )
55     {
56         getchar();
57         ch[i] = getchar();
58     }
59     Solve();
60     return 0;
61 }
View Code

 

posted @ 2014-11-10 19:35  A_dan  阅读(236)  评论(0编辑  收藏  举报