给小爷倒杯茶. 2022-12-29 17:24 采纳率: 100%
浏览 22
已结题

这个问题应该从哪个方向入手?

共有32只球队
欧洲:法国、西班牙、波兰、丹麦、荷兰、德国、威尔士、英格兰、比利时、塞尔维亚、克罗地 亚、瑞士、葡萄牙
亚洲:中国、伊朗、澳大利亚、沙特、日本、韩国
南美洲:巴西、厄瓜多尔、阿根廷、乌拉圭
中北美及加勒比:美国、哥斯达黎加、加拿大、墨西哥
非洲:加纳队、突尼斯队、摩洛哥队、塞内加尔队、喀麦隆队
其中第一档球队分别是:法国、西班牙、德国、英格兰、葡萄牙、巴西、阿根廷、荷兰
第二档球队是: 波兰、丹麦、比利时、中国、喀麦隆、乌拉圭、日本、克罗地亚
现在分组规则如下:
●共分8个组,分别:A组B组C组D组E组F组G组H组
●每组只能有一支第一档球队,只能有一只第二档球队;
●每组一共有四支球队。非第一档、非第二档球队随机进行某一组
●小组积分前两名出线,开始淘汰赛
●出线后对阵图如下:后面CD /EF/ GH类似对阵
【可以参考2022年卡塔尔世界杯规则:
https://www.5068.com/zhishi/a544080.htnl

img

请编写程序:完成年中国世界杯的赛事编排,要求如下:
1、显示各小组分组情况
2、显示总共有多少场比赛场次
3、设计方法:判断中国队会遇到巴西队吗?如果遇到是什么时候碰到[小组赛、1/8.
1/4、半决赛、决赛]?

  • 写回答

1条回答 默认 最新

  • 流比 2022-12-29 17:42
    关注
    import random
    
    teams = ["France", "Spain", "Poland", "Denmark", "Netherlands", "Germany", "Wales", "England", "Belgium", "Serbia", "Croatia", "Switzerland", "Portugal", "China", "Iran", "Australia", "Saudi Arabia", "Japan", "South Korea", "Brazil", "Ecuador", "Argentina", "Uruguay", "USA", "Costa Rica", "Canada", "Mexico", "Ghana", "Tunisia", "Morocco", "Senegal", "Cameroon"]
    first_tier = ["France", "Spain", "Germany", "England", "Portugal", "Brazil", "Argentina", "Netherlands"]
    second_tier = ["Poland", "Denmark", "Belgium", "China", "Cameroon", "Uruguay", "Japan", "Croatia"]
    groups = []
    
    # assign teams to groups
    for i in range(8):
      group = []
      group.append(first_tier[i])
      group.append(second_tier[i])
      for j in range(2):
        team = random.choice(teams)
        while team in first_tier or team in second_tier or team in group:
          team = random.choice(teams)
        group.append(team)
      groups.append(group)
    
    # print groupings
    print("Groupings:")
    for i in range(8):
      print("Group " + chr(ord('A') + i) + ": " + ", ".join(groups[i]))
    
    # generate match schedule
    matches = []
    for i in range(8):
      for j in range(3):
        for k in range(j+1, 4):
          matches.append((groups[i][j], groups[i][k]))
    
    # print number of matches
    print("\nTotal number of matches: " + str(len(matches)))
    
    # function to check if China will play Brazil
    def will_play_brazil(stage):
      if stage == "group":
        for i in range(8):
          if "China" in groups[i] and "Brazil" in groups[i]:
            return True
        return False
      elif stage == "knockout":
        if (len(matches) - len(groups) * 6) % 8 < 4:
          # China is in top half of knockout bracket
          if (matches[-1][0] == "China" and matches[-1][1] == "Brazil") or (matches[-1][1] == "China" and matches[-1][0] == "Brazil"):
            return True
          else:
            return False
        else:
          # China is in bottom half of knockout bracket
          if (matches[-5][0] == "China" and matches[-5][1] == "Brazil") or (matches[-5][1] == "China" and matches[-5][0] == "Brazil"):
            return True
          else:
            return False
    
    # check if China will play Brazil
    if will_play_brazil("group"):
      # print when China will play Brazil (if they do at all)
      print("\nChina will play Brazil in the group stage.")
    elif will_play_brazil("knockout"):
      print("\nChina will play Brazil in the knockout stage.")
    else:
      print("\nChina will not play Brazil in this World Cup.")
    
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 1月6日
  • 已采纳回答 12月29日
  • 创建了问题 12月29日

悬赏问题

  • ¥150 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装