본문 바로가기

python-algorithm1422

백준 21867 Java Bitecode https://www.acmicpc.net/problem/21867 21867번: Java Bitecode 첫째 줄에 코드의 길이를 나타내는 정수 $N$이 주어진다. ($1 \leq N \leq 200\,000$) 둘째 줄에 알파벳 대문자로 이루어진 코드 $S$가 주어진다. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 def sol(s): to_be_changed = 'JAV' for alphabet in to_be_changed : s = s.replace(alphabet, '') if len(s) == 0: return 'nojava' else: return s if __name__ == '__main__': len_s = int(input()) s = in.. 2022. 12. 3.
백준 23627 driip https://www.acmicpc.net/problem/23627 23627번: driip 드립이가 생각하기에 주어진 문자열이 귀여우면 "cute", 그렇지 않으면 "not cute"를 출력한다. (따옴표 제외) www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 def sol(s): target = 'driip' if s.endswith(target) : return 'cute' else : return 'not cute' if __name__ == '__main__': s = input() print(sol(s)) cs endswith 함수를 사용하시면 쉽게 구현이 가능합니다. Use endswith function 2022. 12. 2.
백준 6246 풍선 놀이 https://www.acmicpc.net/problem/6246 6246번: 풍선 놀이 매년 가을 대전에서 열리는 대학생 프로그래밍 대회의 묘미 중 하나는 풍선 놀이이다. 시상식에서 스코어보드 공개를 기다리다가 심심해지면, 주위에 있는 풍선을 엮어서, 대회장을 가로지르는 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 def sol(n, q): balloons = [1]*(n+1) balloons[0] = 0 for _ in range(q): l, i = map(int, input().split()) for j in range(l, n+1, i): balloons[j] = 0 print(sum(balloons)) if __name__ == '__main__': n.. 2022. 12. 2.
백준 14914 사과와 바나나 나눠주기 https://www.acmicpc.net/problem/14914 14914번: 사과와 바나나 나눠주기 아름이가 나누어 줄 수 있는 경우를 모두 출력해야 하며, 각 경우마다 친구의 수, 사과 개수, 바나나 개수 차례로 한 줄에 각각 빈칸으로 구분하여 출력한다. 각 경우마다 중복없이 한 번만 출력 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 def sol(apple, banana): end = min(apple,banana) +1 for i in range(1, end): if apple%i == 0 and banana%i == 0 : print(i, apple//i, banana//i) if __name__ == '__main__': apple, banana = m.. 2022. 12. 2.
백준 11800 Tawla https://www.acmicpc.net/problem/11800 11800번: Tawla 각 테스트마다 상근이와 창영이가 외쳐야 할 문장을 "Case n:" ( "" 제외 ) 을 포함하여 출력하시오. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 def sol(n): if n == 1: return 'Yakk' elif n == 2: return 'Doh' elif n == 3: return 'Seh' elif n == 4: return 'Ghar' elif n == 5: return 'Bang' elif n == 6: return 'Sh.. 2022. 12. 1.
백준 14614 Calculate! https://www.acmicpc.net/problem/14614 14614번: Calculate! 입력의 첫째 줄에 A, B, C가 공백으로 구분되어 주어진다. (1 ≤ A, B ≤ 108, 1 ≤ C ≤ 10100) www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 def sol(a, b, c): if c%2 == 1: return a^b else: return a if __name__ == '__main__': a, b, c = map(int, input().split()) print(sol(a, b, c)) Colored by Color Scripter cs https://sunchol21.tistory.com/1293 백준 12833 XORXORXOR https://www.ac.. 2022. 12. 1.
백준 3765 Celebrity jeopardy https://www.acmicpc.net/problem/3765 3765번: Celebrity jeopardy It’s hard to construct a problem that’s so easy that everyone will get it, yet still difficult enough to be worthy of some respect. Usually, we err on one side or the other. How simple can a problem really be? Here, as in Celebrity Jepoardy, questions www.acmicpc.net 1 2 3 4 5 6 7 if __name__ == '__main__': while True: try: s = input.. 2022. 11. 30.
백준 14954 Happy Number https://www.acmicpc.net/problem/14954 14954번: Happy Number Your program is to read from standard input. The input consists of a single line that contains an integer, n (1 ≤ n ≤ 1,000,000,000) www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 def sol(n): start_num = int(n) num_check =[] while True: check_num =0 for i in n: check_num+=int(i)**2 n = check_num if n == 1: return 'HAP.. 2022. 11. 30.
백준 12778 CTP공국으로 이민 가자 https://www.acmicpc.net/problem/12778 12778번: CTP공국으로 이민 가자 신생국가 CTP공국은 자신들만의 글자가 없다. CTP공국의 왕 준형이는 전 세계 표준 언어인 알파벳을 사용하기로 했다. 하지만 숫자에 미친 사람들이 모인 CTP공국 주민들은 알파벳을 사용할 때 평 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 def sol(type_prob, probs): if type_prob == 'C': answer = [ord(i)-64 for i in probs] elif type_prob == 'N': answer = [chr(int(i) + 64) for i in probs] return answer if __name__ .. 2022. 11. 30.
백준 11104 Fridge of Your Dreams https://www.acmicpc.net/problem/11104 11104번: Fridge of Your Dreams Eirik drinks a lot of Bingo Cola to help him program faster, and over the years he has burned many unnecessary calories walking all the way to the kitchen to get some. To avoid this he has just bought a small fridge, which is beautifully placed next to his www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 def sol(n): answer = int(n,2) return.. 2022. 11. 30.
백준 26082 WARBOY https://www.acmicpc.net/problem/26082 26082번: WARBOY 첫째 줄에 세 양의 정수 $A$, $B$, $C$($1 \le A, B, C \le 1\,000$)가 공백으로 구분되어 주어진다. $\mathbf{\mathit{B}}$는 항상 $\mathbf{\mathit{A}}$의 배수이다. www.acmicpc.net 1 2 3 4 5 6 7 def sol(a,b,c): answer = int(b/a)*3*c return answer if __name__ == '__main__': a, b, c= map(int, input().split()) print(sol(a,b,c)) cs 사칙연산입니다 Just calculate 2022. 11. 30.
백준 25828 Corona Virus Testing https://www.acmicpc.net/problem/25828 25828번: Corona Virus Testing Testing for Corona can be done individually, e.g., 100 people require 100 test kits. Alternatively, the test can be done in groups (pools), e.g., 100 people can be divided into five group of 20 people each and then using only one test kid per group. If one www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 def sol(g,p,t): origin = .. 2022. 11. 30.