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

POJ 2887

时间:2015-06-11 12:46:15      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

#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

标签:

原文地址:http://www.cnblogs.com/gavinsp/p/4568699.html

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