本文主要是介绍1082 MANAGER vector+iterator,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
sicily对格式的要求真是奇葩!
// Problem#: 1082
// Submission#: 2619361
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include<vector>using namespace std;int len,n,nb,op,maxx,minn;
int arr[100];
char ch;int main()
{bool flag=0;while(cin>>len){if(flag) cout<<endl;vector<int> vec1;vector<int>::iterator iter;vector<int> vec2;op=1;cin>>n;for(int i=0;i<n;i++)cin>>arr[i];while(cin>>ch){if(ch=='a'){cin>>nb;vec1.push_back(nb);}else if(ch=='r'){if(op==1){minn=len+1;for(int i=0;i<vec1.size();i++){minn=min(minn,vec1[i]);}for(iter=vec1.begin();iter!=vec1.end();iter++){if(*iter==minn){vec1.erase(iter);break;}}vec2.push_back(minn); }if(op==2){maxx=0;for(int i=0;i<vec1.size();i++){maxx=max(maxx,vec1[i]);}for(iter=vec1.begin();iter!=vec1.end();iter++){if(*iter==maxx){vec1.erase(iter); break;}}vec2.push_back(maxx);}}else if(ch=='p'){cin>>nb;if(nb==1)op=1;else if(nb==2)op=2;}else if(ch=='e'){if(vec1.size()==0)cout<<"-1"<<endl;else{for(int i=0;i<n;i++){cout<<vec2[arr[i]-1]<<endl;}} break;}}flag=1;}return 0;
}
vector的两种遍历:
vector<int>vec;for(int i=0;i<vec.size();i++){vec[i];}
vector<int>vec;vector<int>::iterator iter;for(iter=vec.begin();iter!=vec.end();iter++){*iter;
}
vector 删除
vec.erase(iter);
vec.erase(vec.begin(),vec.end());
这篇关于1082 MANAGER vector+iterator的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!