码迷,mamicode.com
首页 > 其他好文 > 详细

(块状链表) poj 2887

时间:2015-04-02 20:41:53      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

Big String
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:

  1. I ch p: Insert a character ch before the p-th character of the current string. If p is larger than the length of the string, the character is appended to the end of the string.
  2. Q p: Query the p-th character of the current string. The input ensures that the p-th character exists.

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个元素

(块状链表) poj 2887

标签:

原文地址:http://www.cnblogs.com/a972290869/p/4387776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!