标签:
Time Limit: 1000MS | Memory Limit: 131072K | |
Total Submissions: 5936 | Accepted: 1397 |
Description
You are given a string and supposed to do some string manipulations.
Input
The first line of the input contains the initial string. You can assume that it is non-empty and its length does not exceed 1,000,000.
The second line contains the number of manipulation commands N (0 < N ≤ 2,000). The following N lines describe a command each. The commands are in one of the two formats below:
All characters in the input are digits or lowercase letters of the English alphabet.
Output
For each Q command output one line containing only the single character queried.
Sample Input
ab 7 Q 1 I c 2 I d 4 I e 2 Q 5 I f 1 Q 3
Sample Output
a d e
Source
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<ext/rope> using namespace std; using namespace __gnu_cxx; char s[1010],ss[3]; crope a,b; int n; int main() { int x; char c; while(scanf("%s",s)!=EOF) { a=s; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%s",ss); if(ss[0]==‘Q‘) { scanf("%d",&x); cout<<a.at(x-1)<<endl; } else if(ss[0]==‘I‘) { cin>>c>>x; a.insert(x-1,c); } } } return 0; }
rope的部分简单操作
函数 | 功能 |
push_back(x) | 在末尾添加x |
insert(pos,x) | 在pos插入x |
erase(pos,x) | 从pos开始删除x个 |
replace(pos,x) | 从pos开始换成x |
substr(pos,x) | 提取pos开始x个 |
at(x)/[x] | 访问第x个元素 |
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4387776.html