读书人

Python解决codeforces - 七

发布时间: 2013-10-22 16:17:14 作者: rapoo

Python解决codeforces ---- 7


第一题 20A

A. BerOS file systemtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.

A path called normalized if it contains the smallest possible number of characters '/'.

Your task is to transform a given path to the normalized form.

Input

The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.

Output

The path in normalized form.

Sample test(s)input
//usr///local//nginx/sbin
output
/usr/local/nginx/sbin

题意:给定一个字符串路径,但是这个路径可能由多个/来分割,现在要求我们把这个路径简化为Linux下的路径格式,要求末尾不能有/,根目录是一个/

思路:我们利用split()函数把字符串利用/来分割,然后我们利用join()函数来连接非空的值,但是要注意开头一定要有一个/(根目录)

代码:

A. World Football Cuptime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:

读书人网 >perl python

热点推荐