python-algorithm1422 leetcode 844. Backspace String Compare 1 2 3 4 5 6 7 8 9 10 11 12 13 def sol(s): for i in range(len(s)): if '#' in s : if s[0]=='#' : s=s[1:] else : s = s[:s.find('#') - 1] + s[s.find('#') + 1:] else : break return s class Solution: def backspaceCompare(self, s: str, t: str) -> bool: if sol(s)== sol(t) : return True else: return False Colored by Color Scripter cs 2022. 5. 2. leetcode 905. Sort Array By Parity 1 2 3 4 5 6 7 8 9 10 11 def sol(nums): even_list=[] odd_list=[] for i in nums : if i%2 == 0 : even_list.append(i) else : odd_list.append(i) even_list.extend(odd_list) return even_list class Solution: def sortArrayByParity(self, nums: List[int]) -> List[int]: return sol(nums) Colored by Color Scripter cs 2022. 5. 2. codeforces 1352A - Sum of Round Numbers 1 2 3 4 5 6 7 8 9 10 11 def sol(n): if len(n) == 1 : k = 1 else : k = len(n) - n.count('0') ans=[] for i in range(len(n)): if n[i] !='0' : ans.append(n[i]+'0'*(len(n)-i-1)) print(k) print(*ans) for i in range(int(input())): sol(str(input())) Colored by Color Scripter cs 2022. 5. 2. codeforces 1335A - Candies and Two Sisters 1 2 3 4 5 6 def sol(n): if n%2 == 0 : ans = n//2 -1 else : ans = n//2 return ans for i in range(int(input())): print(sol(int(input()))) cs 2022. 5. 2. codeforces 1154A - Restoring Three Numbers 1 2 3 4 5 6 def sol(input_list): a,b,c=input_list[3]-input_list[0],input_list[3]-input_list[1],input_list[3]-input_list[2] print(a,b,c) num_list=sorted(map(int, input().split())) sol(num_list) Colored by Color Scripter cs 2022. 4. 29. codeforces 486A - Calculating Function 1 2 3 4 5 def sol(n): if n%2 == 0 : return (n//2) else: return sol(n-1)-n print(sol(int(input()))) cs 2022. 4. 29. codeforces 155A - I_love_\%username\% 1 2 3 4 5 6 7 8 9 10 11 12 13 14 n=int(input()) cnt = 0 nums=list(map(int, input().split())) strat_min=nums[0] strat_max=nums[0] for i in range(1,n) : if strat_min nums[i] : cnt+=1 strat_max=nums[i] print(cnt) cs 2022. 4. 29. codeforces 977A - Wrong Subtraction 1 2 3 4 5 n, k = map(int, input().split()) for i in range(k): if n%10 == 0 : n//=10 else : n-=1 print(n) cs 2022. 4. 29. codeforces 520A - Pangram 1 2 3 4 5 6 7 n=int(input()) s=input().lower() ans=[] for i in s: if i not in ans : ans.append(i) if 26 == len(ans) : print("YES") else : print("NO") cs 2022. 4. 29. codeforces 1328A - Divisibility Problem 1 2 3 4 5 6 7 8 n=int(input()) for i in range(n): a , b = map(int, input().split()) if a%b == 0 : ans=0 elif a 2022. 4. 29. codeforces 339A - Helpful Maths 1 2 3 4 5 s=sorted(list(map(int, input().split('+')))) ans=str(s[0]) for i in range(1, len(s)): ans+='+%d'%(s[i]) print(ans) Colored by Color Scripter cs 2022. 4. 29. Codeforces 734A - Anton and Danik 1 2 3 4 5 6 7 n=int(input()) s=input() cnt_anton=s.count('A') cnt_danik=s.count('D') if cnt_anton > cnt_danik :print('Anton') elif cnt_anton 2022. 4. 29. 이전 1 ··· 43 44 45 46 47 48 49 ··· 119 다음