社区讨论
为啥cin换成getline全错,原本是对的
P5734【深基6.例6】文字处理软件参与者 6已保存回复 8
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 8 条
- 当前快照
- 1 份
- 快照标识符
- @m2kggmjw
- 此快照首次捕获于
- 2024/10/22 21:02 去年
- 此快照最后确认于
- 2025/11/04 16:30 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
cin.ignore();
getline(cin,str);
for(int i=0;i<n;i++)
{
int x;
cin>>x;
if(x==1)
{
string temp;
cin>>temp;
str+=temp;
cout<<str;
cout<<endl;
}
else if(x==2)
{
int x1,y1;
cin>>x1>>y1;
str=str.substr(x1,y1);
cout<<str;
cout<<endl;
}
else if(x==3)
{
int x1;
cin>>x1;
string temp;
cin>>temp;
str=str.insert(x1,temp);
cout<<str;
cout<<endl;
}
else {
string temp;
cin >> temp;
size_t pos = str.find(temp);
if (pos != string::npos) {
cout << pos << endl;
} else {
cout << -1 << endl;
}
}
}
}
回复
共 8 条回复,欢迎继续交流。
正在加载回复...