POJ 2887
#include <iostream>
#include <string>
#define MAXN 2000
using namespace std; struct node
{
char c;
int place;
}; node _node[MAXN]; int index;
void fun_q(int place);
int len;
string s;
int main()
{
//freopen("acm.acm","r",stdin); int op;
char c;
char c_1;
int q_place;
int i_place;
cin>>s;
cin>>op;
len = s.length();
index = 0; while(op --)
{
cin>>c;
if(c == 'Q')
{
cin>>q_place;
fun_q(q_place);
} else if(c == 'I')
{
cin>>c_1;
cin>>i_place;
if(i_place > len)
{
_node[index].c = c_1;
_node[index].place = len+1;
++ index;
++ len;
}
else
{
++ len;
_node[index].c = c_1;
_node[index].place = i_place;
++ index;
}
} }
} void fun_q(int place)
{ int i;
int p = place;
for(i = index-1; i >= 0; -- i)
{
// cout<<p<<"))))))))))))) "<<endl;
if(_node[i].place < p)
{
-- p;
}
else if(_node[i].place == p)
{
cout<<_node[i].c<<endl;
return;
}
}
cout<<s[p-1]<<endl;
}
POJ 2887的更多相关文章
- POJ 2887 Big String(块状链表)
题目大意 给一个字符串,长度不超过 106,有两种操作: 1. 在第 i 个字符的前面添加一个字符 ch 2. 查询第 k 个位置是什么字符 操作的总数不超过 2000 做法分析 好多不同的做法都可以 ...
- poj 2887 Big String
题目连接 http://poj.org/problem?id=2887 Big String Description You are given a string and supposed to do ...
- POJ 2887:Big String(分块)
http://poj.org/problem?id=2887 题意:给出一个字符串,还有n个询问,第一种询问是给出一个位置p和字符c,要在位置p的前面插入c(如果p超过字符串长度,自动插在最后),第二 ...
- Poj 2887 Big String(块状数组)
Big String Time Limit: 1000MS Memory Limit: 131072K Description You are given a string and supposed ...
- POJ 2887 Big String (块状数组)
题意:给一个字符串(<=1000000)和n个操作(<2000),每个操作可以在某个位置插入一个字符,或者查询该位置的字符.问查询结果. 思路:块状数组. 如果将原来的字符串都存在一起,每 ...
- 好题 线段树对数据的保存+离线的逆向插入 POJ 2887
题目大意:给一个字符串,有插入和询问操作,每次往一个位置插入一个字符或者询问第p个位置的字符是什么. 思路:我们离线询问,逆向把所有的字符都插入给线段树,然后再查询就好了,每次都要记得插入线段树的最后 ...
- Big String(poj 2887)
题意: 给你一个不超过1e6的字符串,和不超过2000次的操作 操作分为两种: 1.将一个字符插入到某个位置的前面 2.询问当前位置的字符 /* 块状链表模板水题(我的智商也就能做这种题了). 观察题 ...
- Poj 2887-Big String Splay
题目:http://poj.org/problem?id=2887 Big String Time Limit: 1000MS Memory Limit: 131072K Total ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
随机推荐
- 2018.12.15 poj3415 Common Substrings(后缀自动机)
传送门 后缀自动机基础题. 给两个字符串,让你求长度不小于kkk的公共子串的数量. 这题可以用后缀自动机解决废话 考虑对其中一个字串建出后缀自动机,然后用另一个在上面跑,注意到如果一个状态有贡献的话, ...
- 开启Greenplum DataBase报错:could not bind IPv4 socket: Address already in use
在运行gpstart时无法开启服务,查看日志看到下图所示错误: 查看日志错误大概是端口已被占用,所以无法重启. 解决方法: (1)利用ipcs查看数据库占用的共享内存.(如下图所示) (2)查看数据库 ...
- Window下同一台服务器部署多个tomcat服务简易教程
第一步:解压两份tomact 分别为tomactserver01和tomactserver02文件夹 第二.配置tomact的环境变量 分别为 第三步:分别修改tomact的bin目录下的catali ...
- 快速创建一个 Servlet 项目(2)
1. 新建一个 webapp 参考 http://www.cnblogs.com/zno2/p/5909019.html 2.调整jdk版本 修改 pom.xml 文件,将jdk 调整为适当的版本,比 ...
- Apache 2.4.28的安装
Apache 2.4.28的安装 1.安装Apache 1.1下载Apache网址:http://httpd.apache.org/ [root@localhost ~]# mkdir -p /roo ...
- linux程序员的proc文件系统
1) 设置core文件存放路径和文件名模式: 设置/proc/sys/kernel/core_pattern,如: echo "core" > /proc/sys/kerne ...
- MATLAB拟合正态分布
clear;clc;close all format compact %% 正态分布的拟合 % 生成随机数 num = 50; y = randn(1000,1); x = 1:num; y = hi ...
- linux下修改root密码以及找回密码的方法
以root身份登陆,执行: # passwd 用户名 (修改密码) # useradd 用户名 (添加用户) 具体示例如下:[root@bogon ~]# passwd root Changing p ...
- js 判断字符串中是否包含某个字符串(转载)
from : https://www.cnblogs.com/ooo0/p/7741651.html String对象的方法 方法一: indexOf() (推荐) var str = " ...
- 基于MATLAB的Sobel边缘检测算法实现
图像边缘就是图像灰度值突变的地方,也就是图像在该部分的像素值变化速度非常之快,就比如在坐标轴上一条曲线有刚开始的平滑突然来个大转弯,在变化出的导数非常大. Sobel算子主要用作边缘检测,它是一离散型 ...