第一题 20A
题意:给定一个字符串路径,但是这个路径可能由多个/来分割,现在要求我们把这个路径简化为Linux下的路径格式,要求末尾不能有/,根目录是一个/
思路:我们利用split()函数把字符串利用/来分割,然后我们利用join()函数来连接非空的值,但是要注意开头一定要有一个/(根目录)
代码:
# solve
def solve():
str = raw_input()
print "/"+"/".join(s for s in str.split("/") if s)
if __name__ == "__main__":
solve()
第二题 19A
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:
-
the final tournament featuresnteams (nis always
even)
-
the firstn / 2teams (according to the standings) come through to the knockout stage
-
the standings are made on the following principle: for a victory a team gets 3 points, for a draw — 1 point, for a defeat — 0 points. In the first place, teams are ordered in the standings in decreasing order of their points; in the second place — in decreasing
order of the difference between scored and missed goals; in the third place — in the decreasing order of scored goals
-
it's written in Berland's Constitution that the previous regulation helps to order the teams without ambiguity.
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.
Output
Outputn / 2lines — 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.
题意:足球世界杯有n支足球队,现在第一轮两两之间较量,赢球的人得3分,平局得1分,输的0分。现在的排名按照得分高低,如果得分一样按照总进球分数和总输球分数的差,如果在一样按照总进球分数高底。要求进入第二轮的n/2支球队,按照字典序输出
思路:利用Python的字典,字典的value是一个列表保存球队得分,总输球分,总进球分
代码:
#coding=utf-8
import os
import sys
# solve
def solve():
n = int(raw_input())
dic = {}
for i in range(n):
str = raw_input()
dic[str] = [0,0,0]
i = n*(n-1)/2
while i:
list = raw_input().split()
tmp1 = list[0].split("-")
tmp2 = list[1].split(":")
i -= 1
if(int(tmp2[0]) > int(tmp2[1])):
dic[tmp1[0]][0] += 3
dic[tmp1[0]][1] += int(tmp2[1])
dic[tmp1[0]][2] += int(tmp2[0])
dic[tmp1[1]][1] += int(tmp2[0])
dic[tmp1[1]][2] += int(tmp2[1])
elif(int(tmp2[0]) == int(tmp2[1])):
dic[tmp1[0]][0] += 1
dic[tmp1[0]][1] += int(tmp2[1])
dic[tmp1[0]][2] += int(tmp2[0])
dic[tmp1[1]][0] += 1
dic[tmp1[1]][1] += int(tmp2[0])
dic[tmp1[1]][2] += int(tmp2[1])
else:
dic[tmp1[0]][1] += int(tmp2[1])
dic[tmp1[0]][2] += int(tmp2[0])
dic[tmp1[1]][0] += 3
dic[tmp1[1]][1] += int(tmp2[0])
dic[tmp1[1]][2] += int(tmp2[1])
# out
ans = sorted(dic.items() , key = lambda value:(value[1][0],value[1][2]-value[1][1],value[1][2]) , reverse = True)
out = []
for i in range(n/2):
out.append(ans[i][0])
out.sort()
for s in out:
print s
# main
if __name__ == "__main__":
solve()
第三题 21A
题目:测试给定的字符串是否满足给定的格式
思路:不解释,题目数据很变态
代码:
#coding=utf-8
import os
import sys
def isOk(ch):
if (ch.isalpha() or ch.isdigit() or ch == '_'):
return True
return False
# solve
def 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"
# main
if __name__ == "__main__":
print solve()
分享到:
相关推荐
在python和bash中使用简单的解析和检查实现,以解决Codeforce中的竞赛。\ 安装 git clone " https://github.com/siddharth17196/codeforces-cli.git " cd codeforces-cli/scripts bash install.sh 将以下内容添加...
Codeforces-Round-492-:解决问题shorturl.atetAIW
codeforces-scraper:刮除来自codeforces的解决方案
:exploding_head: :exploding_head: :female_sign: 我准备链接问题和解决方案 :person_raising_hand: :female_sign: 您已克隆并尝试以下操作:使用Python代码,必须先下载python然后再运行它 :star: :female_sign: ...
codeforces-crawler 一个建议问题,进行虚拟竞赛并为编码平台codeforce的用户显示用户统计信息的网站。 网站链接: 要求 安装要求 导航到目录并运行 点安装-r requirements.txt 运行项目 导航到目录并运行 python ...
CodeForces 适用于问题的Python解决方案。 用户名: hopper19
Codeforces解决方案
单击问题名称以访问Codeforces上的原始问题页面,进行解决,然后返回此处并重复。 祝你好运,高评价! 链接到已部署的应用程序 链接到Codeforces博客 注意 随时提出有关错误/改进的问题。 如果对存储库有任何帮助...
Codeforces解决方案该存储库包含我在codeforces.com上提交并接受的各种问题的解决方案。
Python竞争性编程解决方案 此仓库由My Python解决方案组成,用于解决LeetCode,HackerEarth,GeeksforGeeks,Codechef等各种问题。 解决方案将定期更新。
Codeforces问题解决方案
codeforces解决方案个人资料链接
Codeforces - 比赛于凌晨 12.30 开始 635 Div 2 (16-04-2020) - 排名 11707/21686 参与者 637 Div 2 (24-04-2020) - 排名 12511/23207 参与者 638 Div 2 (02-05-2020) - 排名 9926/24059 参与者 639 Div 2 未评级 ...
cp工具 cp-tool是一个自动生成器,用于解决不同在线法官的问题。 它收集了在线法官解决的所有问题,并为... cp-tool -c init -j codeforces 您会被要求 处理 例如: shifat57 存储库名称(将根据存储库名称创建一个文
Codeforces_Problemset_Solution Codeforces问题的解决方案将在这里上传。 我将尝试使用C ++解决大多数问题。
如果解决方案已经存在,则将不会合并。 遵循命名约定。 例如:107D。 问题的名称.cpp 我在编码时经常忘记的事情: 使用lambda在python3中排序: 假设x是一个元组,并且排序将取决于x [0],如果x [0]相等,则x [1]...
力编码器 无需打开网站即可解决 CodeForces Round 问题! 文档和使用方法即将推出
跟踪您的竞争对手一个命令行实用程序,可以在Spoj,Codechef,Codeforces等各种在线法官上跟踪您的竞争对手。 想要查看您在Codechef上的朋友状态,或想要解决竞争对手在SPOJ上遇到的所有问题。 尝试跟踪您的竞争对手...
这种工具可以自动从codeforces找到高质量的Python解决的任务。 我写这个工具是为了帮助我找到好的资源来提高我的 Python 技能。 cd codeforces python solution-finder.py (number of the contest, e.g. 988) ...
解决 CodeForces 问题