본문 바로가기

전체 글1543

백준 32929 UOS 문자열 https://www.acmicpc.net/problem/32929 1234567891011121314def sol(n):    n -= 1    if n % 3 == 0:        return "U"    elif n % 3 == 1:        return "O"    elif n % 3 == 2:        return "S"  if __name__ == '__main__':    n = int(input())    print(sol(n)) cs넘나 쉬운것.. 2024. 12. 18.
백준 27058 Message Decowding https://www.acmicpc.net/problem/27058 12345678910111213141516171819202122232425def sol(encryption, message ):    answer = ""    for char in message:        is_upper = False        if char.isupper() :            is_upper = True        if char == " ":            answer += " "            continue        decoded_char = encryption[ord(char.lower()) - 97]         if is_upper:            answer += deco.. 2024. 12. 16.
백준 4775 Spelling Be https://www.acmicpc.net/problem/4775 1234567891011121314151617181920212223242526if __name__ == '__main__':    num_word = int(input())     word_dict = {}    cnt = 1    #word_dict = [input() for i in range(n)]    for i in range(num_word):        word_dict[input()] = 1    n = int(input())    for i in range(1, n+1):        not_exist = []        while True:            s = input()             if s == .. 2024. 12. 3.
백준 18698 The Walking Adam https://www.acmicpc.net/problem/18698 1234567891011def sol(steps):    first_fall_down = steps.split("D")    return len(first_fall_down[0])   if __name__ == '__main__':    n = int(input())    for i in range(n):        steps = input()        print(sol(steps))cs사실 이 문제는 U를 선형탐색하면서 조건에 따라 카운팅 해도 되지만그럼 길어지므로 차라리 D를 기준으로 쪼개는게 더 빠를것 같아요 2024. 12. 3.
백준 32498 Call for Problems https://www.acmicpc.net/problem/32498 1234if __name__ == '__main__':    n = int(input())    nums = [1 for num in range(n) if int(input()) % 2 == 1]    print(len(nums))Colored by Color Scriptercs 2024. 11. 27.
백준 32384 사랑은 고려대입니다 https://www.acmicpc.net/problem/32384 12345678910def sol(n):    answer = ["LoveisKoreaUniversity" for i in range(n)]    print(*answer)   if __name__ == '__main__':    n = int(input())    sol(n) Colored by Color Scriptercs조건문이나 다른방식으로 출력해도 되는데가장 pythonic 하게 풀려면 list comprehension 과 unpacking 해서 출력하면 깔끔하게 해결가능 2024. 11. 27.
leetcode 3330. Find the Original Typed String I https://leetcode.com/problems/find-the-original-typed-string-i/description/ 1234567891011class Solution:    def possibleStringCount(self, word: str) -> int:        answer = 1        current_alphabet = word[0]        for i in range(1, len(word)):            if word[i] == word[i - 1]:                answer += 1                            else:                                current_alphabet = word.. 2024. 10. 27.
백준 32260 A + B https://www.acmicpc.net/problem/32260 123456#include "aplusb.h" int sum(int A, int B) {  return A + B ;} cs 2024. 10. 27.
백준 32154 SUAPC 2024 Winter https://www.acmicpc.net/problem/32154 1234567891011121314151617181920def sol(rank_num):    answer = {1: [11, ["A", "B", "C", "D", "E", "F", "G", "H", "J", "L", "M"]]        , 2: [9, ["A", "C", "E", "F", "G", "H", "I", "L", "M"]]        , 3: [9, ["A", "C", "E", "F", "G", "H", "I", "L", "M"]]        , 4: [9, ["A", "B", "C", "E", "F", "G", "H", "L", "M"]]        , 5: [8, ["A", "C", "E", "F", "G", ".. 2024. 10. 27.
3300. Minimum Element After Replacement With Digit Sum https://leetcode.com/problems/minimum-element-after-replacement-with-digit-sum/123456class Solution:    def minElement(self, nums: List[int]) -> int:                answer = [sum(map(int, str(nums[i]))) for i in range(len(nums))]         return min(answer)Colored by Color Scriptercslist comprehension과 각 자리수 합을 구하기 위해서원본 데이터 타입을 문자열로 타입 캐스팅해서 사용합니다. 2024. 10. 5.
leetcode 3210. Find the Encrypted String https://leetcode.com/problems/find-the-encrypted-string/description/12345678class Solution:    def getEncryptedString(self, s: str, k: int) -> str:        answer = ""         for i in range(len(s)):            answer += s[(i+k)%len(s)]                return answerColored by Color Scriptercs문자열 s 를 rotate 하는 느낌으로 구현 2024. 9. 23.
3194. Minimum Average of Smallest and Largest Elements https://leetcode.com/problems/minimum-average-of-smallest-and-largest-elements/description/12345678910class Solution:    def minimumAverage(self, nums: List[int]) -> float:        nums.sort()        averages = []        for i in range(len(nums)//2):            averages.append((nums[i] + nums[-(i+1)])/2)                return min(averages)         Colored by Color Scriptercs 2024. 9. 21.