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 != '\n'&&c != EOF) {
21         s[i++] = c;
22         c = getchar();
23     }
24     s[i] = '\0';
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 }

 

转载于:https://www.cnblogs.com/ohyee/p/5251980.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值