问题描述
编写一个程序,先输入一个字符串str(长度不超过20),再输入单独的一个字符ch,然后程序会把字符串str当中出现的所有的ch字符都删掉,从而得到一个新的字符串str2,然后把这个字符串打印出来。
输入格式:输入有两行,第一行是一个字符串(内部没有空格),第二行是一个字符。
输出格式:经过处理以后的字符串。
输入输出样例
样例输入
123-456-78
-
样例输出
12345678
Attention:此题的坑爹之处在于,如果字符串为空字符串,需要用getline才能读取到。
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
char ch;
string str,str1="";
getline(cin,str);
cin>>ch;
for(int i=0;i<str.length();i++)
{
if(str[i]!=ch)
str1+=str[i];
}
cout<<str1<<endl;
return 0;
}