首页 > 试题广场 >

字符串去特定字符

[编程题]字符串去特定字符
  • 热度指数:10364 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
输入字符串s和字符c,要求去掉s中所有的c字符,并输出结果。

输入描述:
测试数据有多组,每组输入字符串s和字符c。


输出描述:
对于每组输入,输出去除c字符后的结果。
示例1

输入

heallo
a

输出

hello
while True:
    try:
        s=input().strip()
        c=input().strip()
        s=s.replace(c,'')
        print(s)
    except:
        break
发表于 2019-08-08 21:09:02 回复(0)
while True:
    try:
        print(input().replace(input(),""))
    except:
        break

一行搞定。

编辑于 2017-09-12 15:34:34 回复(1)
try:
    while 1:
        s, c = raw_input(), raw_input()
        print s.replace(c, '')
except:
    pass

发表于 2016-12-26 21:18:33 回复(0)