본문 바로가기

python-algorithm1422

백준 11557 Yangjojang of The Year https://www.acmicpc.net/problem/11557 11557번: Yangjojang of The Year 입학 OT때 누구보다도 남다르게 놀았던 당신은 자연스럽게 1학년 과대를 역임하게 되었다. 타교와의 조인트 엠티를 기획하려는 당신은 근처에 있는 학교 중 어느 학교가 술을 가장 많이 먹는지 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 def sol(univ): return max(univ)[1] n=int(input()) for i in range(n): s=int(input()) univ=[] for j in range(s): name, drink=input().split() drink=int(drink) univ.append([drink,nam.. 2022. 10. 5.
백준 25642 젓가락 게임 https://www.acmicpc.net/problem/25642 25642번: 젓가락 게임 용태와 유진이가 게임을 플레이했을 때 용태가 이기게 된다면 yt 를, 유진이가 이긴다면 yj 를 출력한다. www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 def sol(a,b): while a=5: return 'yj' a,b=map(int,input().split()) print(sol(a,b)) cs 이 문제는 두 수를 입력 받아서 서로를 더하는데 5이상이 되면 지는 게임입니다. (In this problem, Input are Two integers, adding each other, if a number become over 5, he/she will lose) 2022. 10. 5.
백준 2605 줄 세우기 https://www.acmicpc.net/problem/2605 2605번: 줄 세우기 점심시간이 되면 반 학생 모두가 한 줄로 줄을 서서 급식을 탄다. 그런데 매일 같이 앞자리에 앉은 학생들이 앞에 줄을 서 먼저 점심을 먹고, 뒷자리에 앉은 학생들은 뒤에 줄을 서 늦게 점심을 www.acmicpc.net 1 2 3 4 5 6 7 8 def sol(n,nums): answer=[] for i in range(1,n+1): answer.insert(nums[i-1],i) return answer[::-1] n=int(input()) nums=list(map(int, input().split())) print(*sol(n,nums)) cs 이 문제는 정수들을 입력받고 insert하는 내용인데 문제 읽어보면.. 2022. 10. 4.
백준 10988 팰린드롬인지 확인하기 https://www.acmicpc.net/problem/10988 10988번: 팰린드롬인지 확인하기 첫째 줄에 단어가 주어진다. 단어의 길이는 1보다 크거나 같고, 100보다 작거나 같으며, 알파벳 소문자로만 이루어져 있다. www.acmicpc.net 1 2 3 4 5 6 7 8 def sol(s): if s==s[::-1] : return 1 else : return 0 s=input() print(sol(s)) cs 이 문제는 문자열을 입력받고 그 문자열이 팰린드롬(앞으로 읽거나 거꾸로 읽어도 똑같은 문자열)인지 판단하는 문제 (This problem is a problem of receiving a string as input and determining whether the string is.. 2022. 10. 4.
백준 2999 비밀 이메일 https://www.acmicpc.net/problem/2999 2999번: 비밀 이메일 정인이는 원래 "bombonisuuladici"를 보내려고 했다. 이 메시지는 16글자이므로, 정인이는 1*16, 2*8, 4*4 행렬을 선택할 수 있다. R이 가장 큰 것은 4*4이므로, 4*4를 선택한다. 정인이가 만든 행렬은 다음과 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 def cal(n): r,c=0,0 for i in range(1, n): if n%i==0 and i 2022. 10. 3.
백준 baekjoon 2846 오르막길 https://www.acmicpc.net/problem/2846 2846번: 오르막길 상근이는 자전거를 타고 등교한다. 자전거 길은 오르막길, 내리막길, 평지로 이루어져 있다. 상근이는 개강 첫 날 자전거를 타고 가면서 일정 거리마다 높이를 측정했다. 상근이는 가장 큰 오르 www.acmicpc.net 이 문제는 정수를 입력받아서 그 정수들의 부분수열이 증가(단조증가 X)하는 경우에서 부분수열의 시작과 끝의 차이가 가장 큰 경우를 출력하는 문제입니다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 def sol(n,nums): end=0 start = nums[0] for i in range(n-1): if nums[i] 2022. 9. 29.
백준 11005 진법 변환 2 https://www.acmicpc.net/problem/11005 11005번: 진법 변환 2 10진법 수 N이 주어진다. 이 수를 B진법으로 바꿔 출력하는 프로그램을 작성하시오. 10진법을 넘어가는 진법은 숫자로 표시할 수 없는 자리가 있다. 이런 경우에는 다음과 같이 알파벳 대문자를 www.acmicpc.net 이 문제는 특정 정수를 입력받으면 N진법으로 변환해서 출력하는 문제입니다. 크게 문제는 어려운게 없고 while문 구조상 나머지가 append되는 순서가 거꾸로 될 필요가 있습니다. ex)16을 2진법으로 저 예제처럼 돌린다고 가정하면 위 그림과 같겠죠? 우리는 1000 을 출력해야되는데 저 구조상은 0001이 되니까 reverse 시켜줍니다 그리고 for문에서 10이상인 경우 처리해줍니다... 2022. 9. 28.
백준 25183 인생은 한 방 https://www.acmicpc.net/problem/25183 25183번: 인생은 한 방 문자열 $S$의 부분 문자열이란, 문자열의 연속된 일부를 의미한다. 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 def check(s1,s2): if abs(ord(s1) - ord(s2))==1: return True else: return False def sol(n,s): cnt=1 for i in range(1,n): if cnt==5: return True if check(s[i],s[i-1]): cnt += 1 else : cnt = 1 if cnt == 5: return True else : retur.. 2022. 9. 27.
백준 25558 내비게이션 https://www.acmicpc.net/problem/25558 25558번: 내비게이션 1번 내비게이션이 안내한 경로는 $(0,0) \rightarrow (11,1) \rightarrow (9,9) \rightarrow (10,10)$으로, 총 거리는 $12 + 10 + 2 = 24$이다. 2번 내비게이션이 안내한 경로는 $(0,0) \rightarrow (1,12) \rightarrow (9,9) \ri www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import sys def cal(a,b,c,d): return abs(c-a)+abs(d-b) n = int(sys.stdin.readline()) distance_list=[] s.. 2022. 9. 26.
백준 25576 찾았다 악질 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 pyimport sys n,m=map(int,sys.stdin.readline().split()) ral=list(map(int, sys.stdin.readline().split())) cnt=n-1 standard=0 for i in range(n-1): compare=list(map(int, sys.stdin.readline().split())) trend_sum=0 for j in range(m): trend_sum+=abs(ral[j]-compare[j]) if trend_sum > 2000: standard+=1 if standard>=cnt/2: print("YES") else : print("NO") Colored b.. 2022. 9. 24.
백준 25495 에어팟 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 def sol(nums): current_phone=nums[0] current_battery = 2 accumulate_cnt= 1 for i in range(1, len(nums)): if current_battery >= 100: current_phone = 0 current_battery = 0 accumulate_cnt = 1 if current_phone == nums[i]: accumulate_cnt += 1 current_battery += 2**accumulate_cnt else : accumulate_cnt = 1 current_battery +=2 current_.. 2022. 9. 22.
leetcode 2413. Smallest Even Multiple 1 2 3 4 5 6 class Solution: def smallestEvenMultiple(self, n: int) -> int: if n%2==0: return n else : return n*2 cs 이 문제는 정수를 입력받으면 2와 그 정수의 최소 공배수를 구하면 됩니다. 다만 유클리드 호제법(https://ko.wikipedia.org/wiki/%EC%9C%A0%ED%81%B4%EB%A6%AC%EB%93%9C_%ED%98%B8%EC%A0%9C%EB%B2%95)을 통해 구할수도 있지만 해당 문제는 주어진 정수가 홀수이냐 짝수이냐에 따라 조건문만 나누면 되서 더 쉽습니다 2022. 9. 22.