Python解决codeforces ---- 7
第一题 20A
A. BerOS file systemtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputThe 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.
InputThe 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.
OutputThe path in normalized form.
Sample test(s)input//usr///local//nginx/sbinoutput
/usr/local/nginx/sbin
题意:给定一个字符串路径,但是这个路径可能由多个/来分割,现在要求我们把这个路径简化为Linux下的路径格式,要求末尾不能有/,根目录是一个/
思路:我们利用split()函数把字符串利用/来分割,然后我们利用join()函数来连接非空的值,但是要注意开头一定要有一个/(根目录)
代码:
A. World Football Cuptime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputEveryone 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:
You are asked to write a program that, by the given list of the competing teams and the results of all the matches, will find the list of teams that managed to get through to the knockout stage.
InputThe first input line contains the only integer n (1?≤?n?≤?50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n?-?1)?/?2 lines describe the held matches in the format name1-name2 num1:num2, wherename1, name2 — names of the teams; num1, num2 (0?≤?num1,?num2?≤?100) — amount of the goals, scored by the corresponding teams. Accuracy of the descriptions is guaranteed: there are no two team names coinciding accurate to the letters' case; there is no match, where a team plays with itself; each match is met in the descriptions only once.
OutputOutput n?/?2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.
Sample test(s)input4ABCDA-B 1:1A-C 2:2A-D 1:0B-C 1:0B-D 0:3C-D 0:3output
ADinput
2aAa-A 2:1output
a
题意:足球世界杯有n支足球队,现在第一轮两两之间较量,赢球的人得3分,平局得1分,输的0分。现在的排名按照得分高低,如果得分一样按照总进球分数和总输球分数的差,如果在一样按照总进球分数高底。要求进入第二轮的n/2支球队,按照字典序输出
思路:利用Python的字典,字典的value是一个列表保存球队得分,总输球分,总进球分
代码:
A. Jabber IDtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard outputJabber ID on the national Berland service ?Babber? has a form <username>@<hostname>[/resource], where
There are the samples of correct Jabber IDs: mike@codeforces.com, 007@en.codeforces.com/contest.
Your task is to write program which checks if given string is a correct Jabber ID.
InputThe input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.
OutputPrint YES or NO.
Sample test(s)inputmike@codeforces.comoutput
YESinput
john.smith@codeforces.ru/contest.icpc/12output
NO
题目:测试给定的字符串是否满足给定的格式
思路:不解释,题目数据很变态
代码:
#coding=utf-8 import osimport sysdef isOk(ch): if (ch.isalpha() or ch.isdigit() or ch == '_'): return True return False# solvedef solve(): str = raw_input() # judge username pos = str.find('@') if pos <= 0 or str.count('@') != 1: return "NO" for i in range(pos): if not isOk(str[i]): return "NO" # judge hostname str = str[pos+1:] if len(str) == 0: return "NO" while True: pos = str.find('.') if pos == -1: if str.find('/') != -1: break for i in str: if not isOk(i): return "NO" break if pos == 0 or pos == len(str)-1: return "NO" for i in range(pos): if not isOk(str[i]): return "NO" str = str[pos+1:] # judge resource pos = str.find('/') if pos != -1: if pos == 0: return "NO" str = str[pos+1:] if len(str) == 0: return "NO" for i in str: if not isOk(i): return "NO" return "YES"# mainif __name__ == "__main__": print solve()