[伯俊]1296チームの名前付け


質問する



に答える

  • count関数と2のfor文を使用して、問題の条件に従って実現します.
  • tupleとsort関数を使用して、
  • サイズの比較とアルファベット順の比較を同時に行います.
  • コード#コード#

    import sys
    
    def solution() :
        y = sys.stdin.readline().rstrip()
        n = int(sys.stdin.readline())
        std = list('LOVE')
        
        if n == 1 :
            print(sys.stdin.readline().rstrip())
        else :
            res = []
            for _ in range(n) :
                s = sys.stdin.readline().rstrip()
                    
                calc = 1
                for i in range(len(std)) :
                    for j in range(i+1, len(std)) :
                        calc *= (y.count(std[i]) + s.count(std[i])) + (y.count(std[j]) + s.count(std[j]))
                
                res.append((calc % 100, s))
            
            res.sort(key = lambda x : (-x[0], x[1]))
    
            print(res[0][1])
                                     
    solution()