首页 > 试题广场 >

序列中删除指定数字

[编程题]序列中删除指定数字
  • 热度指数:55083 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
有一个整数序列(可能有重复的整数),现删除指定的某一个整数,输出删除指定数字之后的序列,序列中未被删除数字的前后位置没有发生改变。
若序列中有多个指定的数,需要一起删除。

数据范围:序列长度和序列中的值都满足

输入描述:

第一行输入一个整数(0≤N≤50)。

第二行输入N个整数,输入用空格分隔的N个整数。

第三行输入想要进行删除的一个整数。



输出描述:
输出为一行,删除指定数字之后的序列。
示例1

输入

6
1 2 3 4 5 9
4

输出

1 2 3 5 9
示例2

输入

5
1 2 3 4 6
5

输出

1 2 3 4 6
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
while True:
    try:
        arr.remove(m)
    except Exception as e:
        break
print(*arr)

发表于 2024-09-27 23:27:24 回复(0)
n = int(input())
a = list(map(int,input().split()))
b = int(input())
while b in a:
    a.remove(b)
print(*a)

编辑于 2024-02-07 10:08:21 回复(0)
N = int(input())
ln = list(map(int, input().split()))
de_N = int(input())
count = ln.count(de_N)
for i in range(count):
    ln.remove(de_N)
print(*ln)

发表于 2021-08-25 15:03:38 回复(0)