Rqff


私信TA

用户名:ziyoudefeng

访问量:1106

签 名:

等  级
排  名 6382
经  验 1360
参赛次数 0
文章发表 1
年  龄 0
在职情况 学生
学  校 青理
专  业

  自我简介:

解题思路:用vector动态数组存数,剩下的很简单,就写我人生中第一篇题解吧hh

注意事项:注意插入的参数要加上数组的起始地址

参考代码:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
int main(){
	vector<int>s;
	int m,n;
	cin>>m>>n;
	for(int i=1;i<=m;i++){
		int x;
		cin>>x;
		s.push_back(x);
	}
	char order[4];
	int temp;
	while(n--){
		scanf("%s",order);
		if(order[0]=='D'){
			cin>>temp;
			for(int i=0;i<s.size();i++){//遍历动态数组,找到元素下标 
				if(s[i]==temp){
					s.erase(s.begin()+i);
					break;
				}
			}
		}
		else if(order[0]=='A'){
			int temp1,temp2,pos;
			cin>>temp1>>temp2;
			for(int i=0;i<s.size();i++){
				if(s[i]==temp1){
					pos = i;
					break;
				}
			}
			s.insert(s.begin()+pos,temp2);
		}
	}
	cout<<s.size()<<endl;
	for(int i=0;i<s.size()-1;i++){
		cout<<s[i]<<" ";
	}
	cout<<s[s.size()-1]<<endl;
	return 0;
}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区