当前位置: 代码迷 >> 综合 >> SPOJ ADALIST Ada and List(vector的使用)
  详细解决方案

SPOJ ADALIST Ada and List(vector的使用)

热度:15   发布时间:2023-11-06 18:14:55.0

vector的使用会使代码变得很简单


#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
vector <int>a;
vector<int>::iterator it;  int main(){int n , q, cmd, k, num;while(scanf("%d%d", &n,&q) != EOF){a.clear(); a.push_back(0);  while(n--){scanf("%d", &num);a.push_back(num);}while(q--){scanf("%d%d", &cmd, &k);if(cmd == 1){scanf("%d", &num);a.insert(a.begin() + k, num);}else if(cmd == 2){a.erase(a.begin() + k);}else if(cmd == 3){it = a.begin() + k;printf("%d\n", *it);}}} return 0;
}


  相关解决方案