每日刷题42

资源限制
内存限制:256.0MB C/C++时间限制:1.0s Java时间限制:3.0s Python时间限制:5.0s
  编写一个程序,先输入一个字符串str(长度不超过20),再输入单独的一个字符ch,然后程序会把字符串str当中出现的所有的ch字符都删掉,从而得到一个新的字符串str2,然后把这个字符串打印出来。
输入示例:
  123-45-678
  -
输出示例:
  12345678

#include <iostream>
using namespace std;
string s,r;
char ch;
int main(){
    
    
    cin>>s;
    cin >> ch;
    int i = 0;
    while(i<s.length()){
    
    
        if(s[i]!=ch){
    
    
            r = r+s[i];
        }
        i++;
    }
    cout<< r ;


}

猜你喜欢

转载自blog.csdn.net/weixin_47988292/article/details/130126814