C++,样例和第一个案例都能过,但是0分
查看原帖
C++,样例和第一个案例都能过,但是0分
839009
JhonXu楼主2024/1/9 16:52

求大佬不吝赐教,c++代码如下:```cpp #include #include using namespace std;

int main(){ int q=0; string s=""; cin >> q ; cin.ignore();// 清除输入缓冲区中的换行符 getline(cin,s); int i=0; while(i<q){ int t=0,a=0,b=0; string str=""; cin >> t; cin.ignore();// 清除输入缓冲区中的空格 if(t==1){ getline(cin,str); s+=str; cout << s << endl; } if(t==2){ cin >> a >> b; str=s.substr(a,b); s=str; cout << s << endl; } if(t==3){ cin >> a; cin.ignore();// 清除输入缓冲区中的空格 或者cin >> a >> str; getline(cin,str); s.insert(a,str); cout << s << endl; } if(t==4){ int pos=0; getline(cin ,str); pos= s.find(str); if(pos<s.size()) cout << pos << endl; else cout << -1 << endl; } i++; } return 0; }

2024/1/9 16:52
加载中...