輸入有多行,對應5個操作,以EOF結束
見Sample
使用vector可以很容易解決
한국어<
中文
فارسی
English
ไทย
All Copyright Reserved 2010-2011 SDUSTOJ TEAM
GPL2.0 2003-2011 HUSTOJ Project TEAM
Anything about the Problems, Please Contact Admin:admin
#include<iostream> #include<vector> #include<string> using namespace std; int main() { string l; int m,n,k; vector<int> a; vector<int>::iterator p; ///a.clear(); while(cin>>l){ if(l=="Build"){cin>>m>>n;a.assign(m,n);} else if(l=="Modify"){cin>>m>>n;a[m-1]=n;} else if(l=="Insert"){cin>>m>>n>>k;a.insert(a.begin()+m-1,a.begin()+n-1,a.begin()+k);} else if(l=="Erase"){cin>>m>>n;a.erase(a.begin()+m-1,a.begin()+n);} else if(l=="Print") { cin>>m>>n; int i; for(i=m-1;i<n;i++) { if(i!=n-1) cout<<"["<<i+1<<"]"<<":"<<a[i]<<" "; else cout<<"["<<i+1<<"]"<<":"<<a[i]<<endl; } } } return 0; }
注:
PS:在C++中,能用string的地方盡量不要用數組。(個人觀點!)