[PS] BOJ 15351 / 인생 점수

[PS] BOJ 15351 / 인생 점수
문제 링크: https://www.acmicpc.net/problem/15351
Thumbnail: Photo by Joshua Earle (Unsplash)

풀이

A = 1, B = 2, ..., Z = 26의 꼴로 계산하려면, 아스키 코드로 변환해 현재 알파벳이 몇번째인지 계산하면 됩니다.

for c in content:
    if c == " ":
        continue
    score += ord(c) - ord("A") + 1

전체 코드

input = open(0).readline
for _ in range(int(input().strip())):
    content = input().strip()
    score = 0
    for c in content:
        if c == " ":
            continue
        score += ord(c) - ord("A") + 1
    print("PERFECT LIFE" if score == 100 else score)

solution.py