资源限制
内存限制:256.0MB C/C++时间限制:1.0s Java时间限制:3.0s Python时间限制:5.0s
问题描述
编写一个程序,第一行输入一个字符串str(长度不超过20),第二行输入单独的一个字符ch。要求程序把字符串str当中所有的ch字符都删除,从而得到一个新的字符串,输出新的字符串。
样例输入
123-45-678
-
样例输出
12345678
分析:将字符串拆成一个一个的字符进行判断,是否是第二行的字符,若不是直接输出
#include<bits/stdc++.h>
using namespace std;
int main(){
char str[21];
gets(str);
int len, i;
len=strlen(str);
char delStr;
cin>>delStr;
for(i=0;i<len;i++){
if(str[i]!=delStr){
cout<<str[i];
}
}
return 0;
}