• AOJ 10.目标柏林


    优化!优化!

    读入的字符串包含空格!

    数据量较大,vector string都会降低效率

    简直优化哭了要( ▼-▼ )

     1 #include <cstdio>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <string>
     6 #include <iostream>
     7 #include <vector>
     8 using namespace std;
     9 
    10 #define REP(n) for(int o=0;o<n;o++)
    11 
    12 const int maxn = 1005;
    13 
    14 int read(char s[]) {
    15     char c;
    16     int i = 0;
    17     c = getchar();
    18     if(c == EOF)
    19         return 0;
    20     while(c != '
    '&&c != EOF) {
    21         s[i++] = c;
    22         c = getchar();
    23     }
    24     s[i] = '';
    25     return i;
    26 }
    27 
    28 int main() {
    29     //std::ios::sync_with_stdio(false);
    30     char s[maxn];
    31     while(read(s)) {
    32         int len = (int)strlen(s);
    33         for(int i = len / 2 + 1;i > 0;i--) {
    34             char temp[maxn];
    35             strcpy(temp,s);
    36             int v[maxn];
    37             int it = 0;
    38             for(int j = i;j <= len;j += i)
    39                 v[it++] = j;
    40 
    41             for(int j = 0;j < it;j++) {
    42                 int t = (i % 2 ? j + 1 : j - 1);
    43                 t = t == -1 ? it - 1 : t == it ? t == 0 : t;
    44                 s[v[j] - 1] = temp[v[t] - 1];
    45             }
    46             //cout << " " << s << endl;
    47             //v.erase(v.begin(),v.end());
    48         }
    49         cout << s << endl;
    50     }
    51     return 0;
    52 }
  • 相关阅读:
    软件概要设计
    Jmter进行Rabbitmq测试
    分布式锁
    实用异常
    异常集合
    本地Windows环境安装RabbitMQ Server
    MySQL千万级多表关联SQL语句调优
    mysql数据库多表关联查询的慢SQL优化
    rabbitmq详细配置
    Idea连接服务器docker并部署代码到docker实现一键启动
  • 原文地址:https://www.cnblogs.com/ohyee/p/5251980.html
Copyright © 2020-2023  润新知