본문 바로가기

Algorithm89

[백준] 1339번 단어수학 오랜만에... 처음엔 리스트로 저장하면서 했다가 그럴 필요가 없어서.. ans = 0 value = 9 alphabet = [0] * 26 for i in range(int(input())): bias = 0 for j in input()[::-1]: alphabet[ord(j) - 65] += 10 ** bias bias += 1 alphabet.sort(reverse=True) for i in range(26): if alphabet[i] == 0: break ans += value * alphabet[i] value -= 1 print(ans) 2021. 1. 23.
[백준] 11501번 주식 흠... import sys for i in range(int(input())): stockLen = int(input()) stockData = list(map(int, sys.stdin.readline().split())) stockData.insert(0, 1000001) tempStock = [stockData[-1]] tempVal = stockData[-1] ans = 0 for i in range(stockLen - 1, -1, -1): if stockData[i] < tempVal: tempStock.append(stockData[i]) else: for j in tempStock: ans += tempVal - j tempVal = stockData[i] tempStock = [tempV.. 2021. 1. 14.
[백준] 1213번 팰린드롬 만들기 처음에 접근 했던 방식이 진짜 굉장히 구현자체는 쉬운데... 치명적인 단점이 있어서.. 아 음.. 다시 도전을 해볼까 싶기도 하고.. 아무튼 다른 블로그를 참고한 해답 다시 도전 해봐야겠다 ㅋㅋㅋㅋㅋ def palindrome(str): oddCount = 0 oddChar = '' strAns = '' ans = [0] * 26 for i in str: ans[ord(i) - 65] += 1 for i in range(26): if ans[i] % 2 == 1: oddCount += 1 oddChar = chr(i + 65) if oddCount >= 2: return "I'm Sorry Hansoo" strAns += chr(i + 65) * (ans[i] // 2) return strAns + od.. 2021. 1. 8.
[백준] 11659번 구간 합 구하기 4 import sys N, M = map(int, sys.stdin.readline().split()) inputData = list(map(int, sys.stdin.readline().split())) ans = [inputData[0]] for i in range(1, N): ans.append(ans[i - 1] + inputData[i]) for i in range(M): x, y = map(int, sys.stdin.readline().split()) if x == 1: print(ans[y - 1]) else: print(ans[y - 1] - ans[x - 2]) 2020. 12. 4.