python-algorithm1422 codeforces 41A - Translation 1 2 3 4 s1 = input() s2 = input() if s1 == s2[::-1] : print("YES") else : print("NO") cs 2022. 4. 28. codeforces 59A - Word 1 2 3 4 5 6 7 8 9 10 s = input() cnt_lower = 0 cnt_upper = 0 for i in s: if i.isupper() : cnt_upper+=1 elif i.islower() : cnt_lower+=1 if cnt_upper > cnt_lower : s=s.upper() else: s=s.lower() print(s) cs string에서 대문자와 소문자 갯수로 구분해 구현하는 문제입니다. 2022. 4. 28. codeforces 236A. Boy or Girl 1 2 3 4 5 6 7 s=(input()) tmp = [] for i in s: if i not in tmp : tmp.append(i) if len(tmp)%2 != 1 : print('CHAT WITH HER!') else : print('IGNORE HIM!') cs 2022. 4. 28. codeforces 281A. Word Capitalization 1 2 s=(input()) print(s[0].upper()+s[1:]) cs 2022. 4. 28. codeforces 282 A. Bit++ 1 2 3 4 5 6 7 n=int(input()) ans=0 for i in range(n): s=input() if '+' in s : ans+=1 elif '-' in s : ans-=1 print(ans) cs 2022. 4. 28. codeforce 112A. Petya and Strings 1 2 3 4 5 str_1=input().lower() str_2=input().lower() if str_1 > str_2 : print(1) elif str_1 == str_2 : print(0) else : print(-1) cs 2022. 4. 28. codeforce 71A. Way Too Long Words 1 2 3 4 5 6 n=int(input()) for i in range(n): s=input() if len(s) 2022. 4. 28. Codeforces A. Watermelon 1 2 3 4 5 6 s=int(input()) ans='' if (s%2)==0 : ans="YES" else : ans="NO" if s == 2 : ans="NO" print (ans) cs 2022. 4. 28. leetcode 1910. Remove All Occurrences of a Substring 1 2 3 4 5 6 7 class Solution: def removeOccurrences(self, s: str, part: str) -> str: for i in range(len(s)): if part in s: s = s[:s.find(part)] + s[s.find(part) + len(part):] else : break return(s) Colored by Color Scripter cs 처음에는 단순하게 replace로 했다가 문자열 s에서 part 가 시작되는 부분 찾아서 쪼개는 방식으로 코드 작성함 Line 6은 예외처리고 part 가 s에 없는 경우에는 문자열을 쪼개면 안됨! 2022. 4. 26. leetcode 46. Permutations 1 2 3 4 5 6 7 from itertools import permutations class Solution: def permute(self, nums: List[int]) -> List[List[int]]: ans=[] for i in permutations(nums) : ans.append(list(i)) return(ans) Colored by Color Scripter cs 1 2 3 4 5 from itertools import permutations class Solution: def permute(self, nums: List[int]) -> List[List[int]]: ans=list(map(list, (permutations(nums)))) return(ans) Colored by.. 2022. 4. 26. leetcode 2221. Find Triangular Sum of an Array 1 2 3 4 5 6 7 8 class Solution: def triangularSum(self, nums: List[int]) -> int: for j in range(len(nums)-1): tmp=[] for i in range(1,len(nums)): tmp.append( (nums[i]+nums[i-1])%10 ) nums=tmp return(nums[0]) cs 2022. 4. 25. 백준 9012 괄호 1 2 3 4 5 6 7 n=int(input()) for i in range(n) : s=input() for j in range(50) : s=s.replace('()','') if s=='': print('YES') else : print('NO') cs Line 4에서 범위를 50으로 지정한 이유는 문자열의 길이가 최대 50이라 정말 최악의 상황을 가정해서 50을 넣었고 시간복잡도는 최악일때 O(N*50)≒O(N)이 되겠습니다 2022. 4. 22. 이전 1 ··· 44 45 46 47 48 49 50 ··· 119 다음