日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

rope

發(fā)布時間:2024/4/15 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 rope 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

基本操作

頭文件

#include <ext/rope>

命名空間

using namespace __gnu_cxx;

定義

rope<char> c; //等價于crope c; rope<int> t; roep<Type> r;

運算符 “+”:可以連接兩個rope

(rope 或 crope)
運算符 “<< ”和“ >> ”:可由輸入輸出流讀入或輸出。

cout << c << endl;
  • c.length()/c.size() 返回長度/大小

  • push_front(x); //在首部添加x
  • push_back(x); //在末尾添加x

  • c.insert(pos, x); //在pos插入x,x可以是一個元素也可以是一個數(shù)組
  • c.erase(pos, x);//從pos開始刪除x個

  • c.copy(pos, len, x); //把c[pos~(pos+x-1)]復(fù)制到x

  • c.replace(pos, x); //從pos開始換成x

  • c.substr(pos, x); //返回一個rope類型,而且等于c[pos~(pos+x-1)],且兩者互不相干。

  • c.at(x)/c[x]; //訪問第x個元素

\(O(1)\)拷貝歷史版本

指針

rope<Type> *a, *b; a = new rope<Type>; b = new rope<Type> (*a);

非指針

rope<Type> a, b; a = b;

應(yīng)用

Editor

#include <iostream> #include <cstdio> #include <cstring> #include <ext/rope>using namespace std; using namespace __gnu_cxx;const int N = 1 << 22;char ch[N]; crope text;int main() {int t, p = 0;scanf("%d", &t);while (t--) {char op[20];scanf("%s", op);if (op[0] == 'M') scanf("%d", &p);else if (op[0] == 'P') --p;else if (op[0] == 'N') ++p;else if (op[0] == 'I') {int n;scanf("%d", &n);for (int i = 0; i < n; ++i) {do scanf("%c", ch + i);while (ch[i] < 31 || 126 < ch[i]);}ch[n] = 0;text.insert(p, ch);} else if (op[0] == 'D') {int n;scanf("%d", &n);text.erase(p, n);} else {int n;scanf("%d", &n);text.copy(p, n, ch);ch[n] = 0;puts(ch);}}return 0; }

文本編輯器

#include <iostream> #include <cstdio> #include <cstring> #include <ext/rope>using namespace std; using namespace __gnu_cxx;const int N = 1 << 22;char ch[N]; crope tt, rt, tmp;int main() {int t, p = 0;scanf("%d", &t);while (t--) {char op[20];scanf("%s", op);if (op[0] == 'M') scanf("%d", &p);else if (op[0] == 'P') --p;else if (op[0] == 'N') ++p;else if (op[0] == 'I') {int n;scanf("%d", &n);for (int i = 0; i < n; ++i) {do scanf("%c", ch + i);while (ch[i] < 32 || 126 < ch[i]);}ch[n] = 0;int len = tt.length();tt.insert(p, ch);reverse(ch, ch + n);rt.insert(len - p, ch);} else if (op[0] == 'D') {int n, len = tt.length();scanf("%d", &n);tt.erase(p, n);rt.erase(len - p - n, n);} else if (op[0] == 'R') {int n, len = tt.length();scanf("%d", &n);tmp = tt.substr(p, n);tt = tt.substr(0, p) + rt.substr(len - p - n, n) + tt.substr(p + n, len - p - n);rt = rt.substr(0, len - p - n) + tmp + rt.substr(len - p, p);} else if (op[0] == 'G') printf("%c\n", tt[p]);}return 0; }

文藝平衡樹

#include <iostream> #include <cstdio> #include <cstring> #include <ext/rope>using namespace std; using namespace __gnu_cxx;int n, m; rope<int> s, t, tmp;int main() {scanf("%d%d", &n, &m);for (int i = 1; i <= n; ++i)s.push_back(i);for (int i = n; i; --i)t.push_back(i);while (m--) {int l, r;scanf("%d%d", &l, &r);int len = r - l + 1;tmp = s.substr(l - 1, len);s = s.substr(0, l - 1) + t.substr(n - r, len) + s.substr(r, n - r);t = t.substr(0, n - r) + tmp + t.substr(n - l + 1, l);}for (int i = 0; i < n; ++i)printf("%d ", s[i]);puts("");return 0; }

轉(zhuǎn)載于:https://www.cnblogs.com/tkandi/p/9450543.html

總結(jié)

以上是生活随笔為你收集整理的rope的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。