北京郵電1177,replace和reverse的用法
阿新 • • 發佈:2019-02-13
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> using namespace std; int main(){ string str; int n; string demand; while(cin>>str){ scanf("%d",&n); for(int i = 1;i<=n;i++) { cin>>demand; if(demand[0]=='0')//翻轉 { int start = demand[1]-'0'; int len = demand[2]-'0'; reverse(str.begin()+start,str.begin()+start+len); cout<<str<<endl; }else if(demand[0]=='1')//替換 { int start = demand[1]-'0'; int len = demand[2]-'0'; string aa = demand.substr(3,len); str = str.replace(start,len,aa); cout<<str<<endl; } } } }