算法与数据结构实验题 2.1 塔防

1、题目:


2、代码:

#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int value[501];
	int i,j;
	for(i=0;i<n;i++)
	{
		cin>>value[i];
	}
	string str;
	int k;
	for(j=0;j<m;j++)
	{
		cin>>str>>k;
		if(str=="add")
		{
		
			value[n]=k;
			n++;
		}
		else if(str=="del")
		{
			for(int l=k;l<n-1;l++)
			{
				value[l]=value[l+1];
			}
			n--;
			
		}
		else if(str=="cge")
		{
			int number;
			cin>>number;
			value[k]=number;
		}
		else if(str=="qry")
		{
			cout<<value[k]<<endl;
		}
	}
	return 0;
}
posted @ 2016-10-07 23:45  laixl  阅读(211)  评论(0编辑  收藏  举报