首页 > 试题广场 >

删除公共字符

[编程题]删除公共字符
  • 热度指数:49282 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”

输入描述:
每个测试输入包含2个字符串


输出描述:
输出删除后的字符串
示例1

输入

They are students. 
aeiou

输出

Thy r stdnts.
s1 = input()
s2 = input()
for i in s1:
    s2 = s2.replace(i,'')
print(s2)
发表于 2020-07-25 17:56:50 回复(0)
s1 = input()
s2 = input()

res = ""
for i in s1:
    if i in s2:
        continue
    else:
        res += i

print(res)

发表于 2020-05-15 14:44:50 回复(0)
s,target = input(),input()
[print(i,end='') for i in s if i not in target]

发表于 2020-01-18 12:21:58 回复(0)
python 2.7.3
#创建一个新列表,判断字符串1的元素是否在字符串2中,如果不在,新列表添加该元素,在,跳过;可实现删除字符串1 中所有字符串2的元素
s1 = list(raw_input())
s2 = list(raw_input())
new_s = []
for i in range(len(s1)):
    if s1[i]  not in s2:
        new_s.append(s1[i])
print ''.join(new_s)
        
        

发表于 2019-08-26 09:39:18 回复(0)
a=input()
b=input()
for i in b:
    a=a.replace(i,'')
print(a)

发表于 2019-01-04 16:45:47 回复(0)
python:
first_str = input()
second_str = list(input())
for i in second_str:
    first_str = first_str.replace(i, "")
print(first_str)

发表于 2019-01-02 15:50:17 回复(0)
try:
    while(True):
        first = list(input())
        second = set(input())
        result = ""
        for x in first:
            if x not in second:
                result = result + x
        print(result)
except:
    pass

好久没写python代码,语法快忘了:(
编辑于 2018-11-02 09:36:37 回复(0)
import os a = input() b = input() for c in b:  while c in a:  a_del = a.find(c) a = a[:a_del] + a[a_del + 1:] print(a)

编辑于 2018-09-08 15:25:35 回复(0)
Python
n,m = input().split(),input().strip()
ans = []
for each in n:
    temp = []
    for i in each:
        if i not in m:
            temp.append(i)
    ans.append(''.join(temp))
print(' '.join(ans))
这道题的输入格式描述有问题,是两行输入,并不是一行输入用空格分割,浪费了很多时间
发表于 2018-07-08 22:01:50 回复(0)
A=[x for x in input()]
B=[x for x in input()]
for i in B:
    if i in A and i!=' ':
        A=[x for x in A if x!=i]
print(''.join(A))


发表于 2018-05-28 11:19:20 回复(1)
s1=input()
s2=input()
for i in s2:
    s1=s1.replace(i,'')#将s2中的每个字符都在s1中替换为空
print(s1)

编辑于 2018-05-25 11:52:55 回复(1)
#! python3
#-*- coding:utf-8 -*-

"""
题目描述
输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。
例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”
输入描述:
每个测试输入包含2个字符串
输出描述:
输出删除后的字符串
示例1
输入
They are students. aeiou
输出
Thy r stdnts.
"""

import sys

def clean_str(str1,str2):
    ""
    for i in str2:
        str1=str1.replace(i,'')
    return str1

if __name__=="__main__":
    ""
    str1=input()
    str2=input()
    print(clean_str(str1,str2))


编辑于 2018-03-12 20:29:12 回复(0)
def delete_string(s1, s2):
    for char1 in s2:
        s = ''
        for char2 in s1:
            if char1 != char2:
                s += char2
        s1 = s
    return s
if __name__ == "__main__":
    s1 = input()
    s2 = input()
    s = delete_string(s1,s2)
    print(s)


发表于 2018-03-07 10:20:45 回复(0)
userinput = input()
target = input()
length = len(target)
counter = 0
while(counter<length):
    userinput = userinput.replace(target[counter],'')
    counter+=1
userinput = userinput.strip()
print(userinput)

发表于 2018-01-26 01:46:54 回复(0)
import re
if __name__ == '__main__':
    s1 = input()
    s2 = '[' + input() + ']'
    ans = re.sub(s2, '', s1)
    print(ans)
发表于 2017-10-01 20:02:21 回复(0)