1、题目:

算法与数据结构实验题 2.1 塔防
算法与数据结构实验题 2.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;
}

相关文章:

  • 2021-06-15
  • 2021-06-23
  • 2021-05-17
  • 2021-05-19
  • 2022-02-19
  • 2021-10-15
  • 2021-06-01
  • 2021-08-09
猜你喜欢
  • 2021-08-28
  • 2021-10-04
  • 2021-05-16
  • 2022-02-05
  • 2021-06-24
  • 2022-12-23
相关资源
相似解决方案