You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
int n ; //n条指令
string s ; //原来的字符串
string a ; //要追加的字符串
int opt ; //操作命令, 1: 追加, 2: 截取, 3: 插入, 4: 查找
int l ; //从第几个开始截取
int cnt ; //截取几个字符
int main ( ) {
cin > > n > > s ;
while ( n - - ) {
cin > > opt ;
switch ( opt ) {
case 1 : //追加
cin > > a ;
//s.append(a);
s + = a ;
cout < < s < < endl ;
break ;
case 2 : //截取
cin > > l > > cnt ;
s = s . substr ( l , cnt ) ;
cout < < s < < endl ;
break ;
case 3 : //插入
cin > > l > > a ;
s . insert ( l , a ) ;
cout < < s < < endl ;
break ;
case 4 : //查找位置
cin > > a ;
auto pos = s . find ( a ) ;
if ( pos = = s . npos ) printf ( " %d \n " , - 1 ) ;
else printf ( " %d \n " , pos ) ;
break ;
}
}
return 0 ;
}