
字符串真是博大精深!!!
一道“字符串水题”卡了我这么久??
关键是gets函数的应用。
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int vis[10000];
int main()
{
char q[10000];
while(gets(q))
{
string s=q;
char c;
scanf("%c",&c);
int pos=s.find(c);
while(pos!=-1)
{
s.erase(pos,1);
pos=s.find(c,pos);
}
cout<<s<<endl;
getchar();///重点!一定要加上!!!
}
}

本文通过一个具体的示例讲解了如何使用C++中的gets函数读取一行字符串,并演示了如何利用标准库函数find和erase来移除指定字符的所有实例。此外,还强调了一个容易被忽视的细节:使用getchar()清除输入缓冲区的重要性。
171万+

被折叠的 条评论
为什么被折叠?



