Easy List Operations

2020年1月17日 1249点热度 0人点赞 0条评论

Easy List Operations

时间: 1ms        内存:32M

描述:

A list is a sequence of or more elements, expressed in this form: [a 1 , a 2 , a 3 , ... , a n ], where each a i
is or more consecutive digits or lowercase letters. i.e. each list begins with a left square bracket,
then zero or more elements separated by a single comma, followed by a right square bracket. There will
be no whitespace characters (spaces, TABs etc) within a list.
In this problem, we use two list operations: append (++) and remove (--).
1. A ++ B: append elements in B to the end of A.
2. A -- B: remove all the elements in B, from A. If something appears more than once in B, remove it that
many times in A. If there are many equal elements in A to choose from, remove them from left to right
(until all occurrences are removed, or there is no need to remove more elements).
Your task is to write a calculator, evaluating simple expressions or the form "list1 ++ list2" or "list1 --
list2".

输入:

There will be at most 10 expressions, one in each line, each having the form "list1 ++ list2" or "list1 --
list2", with no more than 80 characters in total (not counting the newline character). There will be exactly
two spaces in each line: one before and one after the operator. Input ends with a single dot. The input is
guaranteed to satisfy the restrictions stated above.

输出:

For each expression, print its result on a single line.

示例输入:

[1,2,3] ++ [1,2,3]
[a,b,c,t,d,e,t,x,y,t] -- [t]
[a,b,c,t,d,e,t,x,y,t] -- [t,t,t,t]
[123] ++ [456]
.

示例输出:

[1,2,3,1,2,3]
[a,b,c,d,e,t,x,y,t]
[a,b,c,d,e,x,y]
[123,456]

提示:

参考答案:

解锁文章

没有看到答案?微信扫描二维码可免费解锁文章

微信扫描二维码解锁

使用微信扫描二维码打开广告页面后可以立即关闭,再刷新此页面即可正常浏览此文章

所跳转广告均由第三方提供,并不代表本站观点!

已经扫描此二维码?点此立即跳转

code

这个人很懒,什么都没留下

文章评论