zoukankan      html  css  js  c++  java
  • Ropes

    http://www.sgi.com/tech/stl/Rope.html


    1 BZOJ 1507 [NOI2003] Editor

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 #include <queue>
     7 #include <vector>
     8 #include <stack>
     9 #include <map>
    10 #include <set>
    11 #include <cmath>
    12 #include <cctype>
    13 #include <ctime>
    14 #include <ext/rope>
    15  
    16 using namespace std;
    17 using namespace __gnu_cxx;
    18  
    19 #define REP(i, n) for (int i = 0; i < (n); ++i)
    20 #define eps 1e-9
    21 #define SZ(x) ((int)x.size())
    22 #define PI acos(-1.0)
    23  
    24 typedef long long ll;
    25 typedef pair<int, int> pii;
    26 const int maxn = 2e6 + 10;
    27 crope my_rope;
    28 char s[maxn], opt[15];
    29 int q, p, n;
    30 char c;
    31  
    32 int main() {
    33 #ifdef __AiR_H
    34     freopen("in.txt", "r", stdin);
    35 //    freopen("out.txt", "w", stdout);
    36 #endif // __AiR_H
    37     scanf("%d", &q);
    38     while (q--) {
    39         scanf("%s", opt);
    40         if (opt[0] == 'M') { scanf("%d", &p); }
    41         else if (opt[0] == 'I') {
    42             scanf("%d", &n);
    43             for (int i = 0; i < n;) {
    44                 c = getchar();
    45                 if (32 <= c && c <= 126) { s[i++] = c; }
    46             }
    47             s[n] = ''; my_rope.insert(p, s);
    48         } else if (opt[0] == 'D') {
    49             scanf("%d", &n); my_rope.erase(p, n);
    50         } else if (opt[0] == 'G') {
    51             scanf("%d", &n); my_rope.copy(p, n, s);
    52             s[n] = ''; printf("%s
    ", s);
    53         } else if (opt[0] == 'P') { --p; }
    54         else { ++p; }
    55     }
    56     return 0;
    57 }
    View Code

    2 BZOJ 1269 [AHOI2006] 文本编辑器editor

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 #include <algorithm>
     6 #include <queue>
     7 #include <vector>
     8 #include <stack>
     9 #include <map>
    10 #include <set>
    11 #include <cmath>
    12 #include <cctype>
    13 #include <ctime>
    14 #include <ext/rope>
    15  
    16 using namespace std;
    17 using namespace __gnu_cxx;
    18  
    19 #define REP(i, n) for (int i = 0; i < (n); ++i)
    20 #define eps 1e-9
    21 #define SZ(x) ((int)x.size())
    22 #define PI acos(-1.0)
    23  
    24 typedef long long ll;
    25 typedef pair<int, int> pii;
    26 const int maxn = 2e6 + 10;
    27 crope rope1, rope2, t;
    28 char opt[20], s[maxn];
    29 char c;
    30 int q, p, n, len;
    31  
    32 int main() {
    33 #ifdef __AiR_H
    34     freopen("in.txt", "r", stdin);
    35 //    freopen("out.txt", "w", stdout);
    36 #endif // __AiR_H
    37     scanf("%d", &q);
    38     while (q--) {
    39         scanf("%s", opt);
    40         if (opt[0] == 'M') { scanf("%d", &p); }
    41         else if (opt[0] == 'I') {
    42             scanf("%d", &n); len = rope1.length();
    43             for (int i = 0; i < n;) {
    44                 c = getchar();
    45                 if (32 <= c && c <= 126) { s[i++] = c; }
    46             }
    47             s[n] = ''; rope1.insert(p, s);
    48             reverse(s, s + n); rope2.insert(len - p, s);
    49         } else if (opt[0] == 'D') {
    50             scanf("%d", &n); len = rope1.length();
    51             rope1.erase(p, n); rope2.erase(len - p - n, n);
    52         } else if (opt[0] == 'G') { printf("%c
    ", rope1[p]); }
    53         else if (opt[0] == 'P') { --p; }
    54         else if (opt[0] == 'N') { ++p; }
    55         else {
    56             scanf("%d", &n); len = rope1.length();
    57             t = rope1.substr(p, n);
    58             rope1 = rope1.substr(0, p) + rope2.substr(len - p - n, n) + rope1.substr(p + n, len - p - n);
    59             rope2 = rope2.substr(0, len - p - n) + t + rope2.substr(len - p, p);
    60         }
    61     }
    62     return 0;
    63 }
    View Code

  • 相关阅读:
    源码分析shiro认证授权流程
    shiro功能模块
    Java NIO(New I/O)的三个属性position、limit、capacity
    阻塞和非阻塞,同步和异步 总结
    小白科普:Netty有什么用?
    【异常】SSM整合quartz之org.quartz.impl.JobDetailImpl----ClassNotFoundException
    笔记本键盘字母按出来的都是快捷键
    eclipse egit提交方法
    oracle批量insert
    CAS Client 3.2.1 配置详解
  • 原文地址:https://www.cnblogs.com/zhaoyz/p/7683744.html
Copyright © 2011-2022 走看看