1. #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[n]={},x,y; for(int i=0;i<n;i++){ cin>>a[i]; } cin>>x; deque<int> b(a,a+sizeof(a)/sizeof(int)); b.erase(b.begin()+x); for(int i=0;i<b.size();i++){ cout<<b[i]<<" "; } return 0; } 2. #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[n]={},x,y; for(int i=0;i<n;i++){ cin>>a[i]; } cin>>x>>y; deque<int> b(a,a+sizeof(a)/sizeof(int)); b.insert(b.begin()+x-1,y); for(int i=0;i<b.size();i++){ cout<<b[i]<<" "; } return 0; } 3. #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[n]={},x,y; for(int i=0;i<n;i++){ cin>>a[i]; } cin>>x>>y; deque<int> b(a,a+sizeof(a)/sizeof(int)); b.insert(b.begin()+x-1,y); b.erase(b.begin()+x); for(int i=0;i<b.size();i++){ cout<<b[i]<<" "; } return 0; } 4.优化版 #include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; int a[n]={},y; for(int i=0;i<n;i++){ cin>>a[i]; } cin>>y; deque<int> b(a,a+sizeof(a)/sizeof(int)); for(int i=0;i<y;i++){ b.push_back(b.front()); b.pop_front(); } for(int i=0;i<b.size();i++){ cout<<b[i]<<" "; } return 0; }
标签:std,容器,begin,int,cin,sizeof,main From: https://www.cnblogs.com/fushuxuan/p/17937224