a,b = map(int,input().split()) he = str(a + b) if he[0]=='-': print('-',end='') he = he[1:] y = len(he)%3 if y: print(he[:y],end='') else: print(he[:3],end='') y=3 for i inrange(int((len(he)-y)/3)): l = i*3+y print(',',end='') print(he[l:l+3],end='')
# N number of cities # M number of roads # C1 strart # C2 end # team_num number of rescue teams # adjacent 连接矩阵
defDijkstra(C1,C2): dist = [Max for i inrange(N)] # 标记距离长度 dist[C1] = 0 flag_node = [-1for i inrange(N)] # 标记已经确定最短路径的列表 flag_node[C1] = 1 res = [[] for i inrange(N)] # 记录需要的答案 res[C1] = [1,team_num[C1]] p = C1 # 指针节点 for i inrange(N): # 循环直到所有节点都被标记 if flag_node[C2] == 1: # 如果C2已经被确定,退出循环 break # 如果C2未被确定,从当前路径开始寻找下一节点 for i inrange(N): temp_dist = adjacent[p][i] if (flag_node[i] == -1) and (temp_dist != Max): # 查询该节点未确定的通路 if dist[i] > (dist[p] + temp_dist): # 判断是否需要更新 dist[i] = dist[p] + temp_dist res[i] = [res[p][0],res[p][1]+team_num[i]] elif dist[i] == (dist[p] + temp_dist): res[i][0] += res[p][0] if res[i][1] < (res[p][1]+team_num[i]): res[i][1] = res[p][1]+team_num[i] #寻找最小值进行标记 mini = Max for i inrange(N): if flag_node[i] == -1: if dist[i] < mini: mini = dist[i] p = i flag_node[p] = 1 return res[C2]
Max = 1000000 #接收数据 N,M,C1,C2 = map(int,input().split()) team_num = list(map(int,input().split())) # 建立连接矩阵 adjacent = [ [Max for i inrange(N)] for i inrange(N) ] for i inrange(M): a,b,l = map(int,input().split()) adjacent[a][b] = l adjacent[b][a] = l
# 使用Dijkstra算法 # num 总共医疗数量 # long 总路程 answer = Dijkstra(C1,C2) # 如有多个结果res会返回多个列表 print(answer[0],answer[1])
defbfs(ID): global max_depth visited[ID] = True queqe.add_item(treenode(0,tree[ID][0],tree[ID][1])) whilenot queqe.empty(): v = queqe.get_item() nowdepth = v.depth max_depth = max(nowdepth,max_depth) for i in v.child_id: if i notin visited: visited[i] = True if i notin tree: res[nowdepth+1] += 1 else: queqe.add_item(treenode(nowdepth+1,tree[i][0],tree[i][1]))
N,M = map(int,input().split())
if N == 1: print(1) else: tree = {} # 树字典 res = [0for i inrange(N)] # 记录答案列表 visited = {} # 标记访问过的节点 max_depth = 0# 最大树深度 # 构建树结构 for i inrange(M): node_id , k, *child_id = list(input().split()) tree[node_id] = [k,child_id] queqe = queqe() bfs('01') max_depth += 1 for i inrange(max_depth): print(res[i],end = ' ') print(res[max_depth])
1005 Spell It Right (20分)
1 2 3 4 5 6 7 8 9 10 11
N = input() s = 0 dic = ["zero","one","two","three","four",\ "five","six","seven","eight","nine"]
for i in N: s += int(i) for i instr(s)[:-1]: print(dic[int(i)],end=" ") print(dic[int(str(s)[-1])])
1006 Sign In and Sign Out (25分)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
M = int(input()) ID, intime, outtime = input().split() unl_id = ID unl_time = intime l_id = ID l_time = outtime for i inrange(M-1): ID, intime, outtime = input().split() if intime < unl_time: unl_id = ID unl_time = intime if outtime > l_time: l_id = ID l_time = outtime print(unl_id, l_id)