zoukankan      html  css  js  c++  java
  • 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( '
    ' );
    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
  • 相关阅读:
    11 Jun 18 复习,HTTP
    11 Jun 18 Django
    8 Jun 18 复习,mysql
    8 Jun 18 Bootstrap
    7 Jun 18 复习,文件,函数,sorted,colletions
    7 Jun 18 Bootstrap
    pip 使用方法
    http协议 1.1
    mysql 的视图 触发器 事务 存储过程 内置函数 流程控制 索引
    day 29 守护进程/互斥锁/IPC通信机制/生产者消费者模型
  • 原文地址:https://www.cnblogs.com/ADAN1024225605/p/4087902.html
Copyright © 2011-2022 走看看