본문 바로가기

python-algorithm1422

백준 10205 헤라클레스와 히드라 def sol(n,s): for i in s: if i=='c': n+=1 elif i=='b': n-=1 if n==0: return 0 return n k=int(input()) for i in range(k): print("Data Set %d:"%(i+1)) n=int(input()) s=input() print(sol(n,s)) if i!=k-1: print() https://www.acmicpc.net/problem/10205 10205번: 헤라클레스와 히드라 헤라클레스는 그리스 신화의 유명한 비극적인 영웅이다. 그는 제우스의 사생아로 태어났는데, 이때문에 제우스의 아내 헤라는 그를 매우 싫어했다. 그는 매우 강한 힘과 높은 지식을 가졌지만, www.acmicpc.net 조건문과 간단한 문자열.. 2022. 10. 22.
백준 25640 MBTI mbti=input() n=int(input()) answer=0 for i in range(n): if input()==mbti: answer+=1 print(answer) https://www.acmicpc.net/problem/25640 25640번: MBTI 진호는 요즘 유행하는 심리 검사인 MBTI에 관심이 많다. MBTI는 아래와 같이 네 가지 척도로 사람들의 성격을 구분해서, 총 $16$가지의 유형중에서 자신의 유형을 찾을 수 있는 심리 검사이다. 내향( www.acmicpc.net 쉽죠 같은 문자열 카운팅하면 됩니다. Just count same String 2022. 10. 21.
백준 15000 CAPS s=input() print(s.upper()) https://www.acmicpc.net/problem/15000 15000번: CAPS Earth is under attack! Messages need to be sent to the Earth Defense Force (EDF) that makes clear that the situation is dire. The EDF’s strongest forces consist of mechs (huge bipedal robots) that are piloted by Japanese teenagers. To make sure that the www.acmicpc.net 문자열을 전부 대문자로 바꾸면 됩니다 All character should be conve.. 2022. 10. 21.
백준 25372 성택이의 은밀한 비밀번호 def sol(s): answer='no' if len(s)>=6 and len(s) 2022. 10. 20.
백준 1026 보물 https://www.acmicpc.net/problem/1026 1026번: 보물 첫째 줄에 N이 주어진다. 둘째 줄에는 A에 있는 N개의 수가 순서대로 주어지고, 셋째 줄에는 B에 있는 수가 순서대로 주어진다. N은 50보다 작거나 같은 자연수이고, A와 B의 각 원소는 100보다 작거 www.acmicpc.net def sol(nums1,nums2): answer=0 for i in range(len(nums1)): answer+=nums1[i]*nums2[i] return answer n=int(input()) nums1=sorted(list(map(int,input().split()))) nums2=sorted(list(map(int,input().split())), reverse=True) p.. 2022. 10. 19.
프로그래머스 짝수의 합 def solution(n): n//=2 answer = n*(n+1) return answer https://school.programmers.co.kr/learn/courses/30/lessons/120831 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 1부터 n까지의 합 == n(n+1)/2 에서 2를 곱해주면 짝수합이죵 Sum From 1 to n ==n(n+1)/2 multiple two mean Evens' sum 2022. 10. 19.
프로그래머스 두 수의 나눗셈 def solution(num1, num2): answer = int((num1/num2)*1000) return answer https://school.programmers.co.kr/learn/courses/30/lessons/120806 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 2022. 10. 19.
프로그래머스 중복된 숫자 개수 def solution(array, n): answer = array.count(n) return answer https://school.programmers.co.kr/learn/courses/30/lessons/120583 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr list의 count 함수 사용하시면 됩니다 Use count() function 2022. 10. 19.
프로그래머스 배열의 평균값 def solution(numbers): answer = sum(numbers)/len(numbers) return answer https://school.programmers.co.kr/learn/courses/30/lessons/120817 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 쉽죠 2022. 10. 19.
백준 2993 세 부분 def sol(s): len_s = len(s) strings = [] for i in range(1, len_s - 1): for j in range(1, len_s - 1): if i + j 2022. 10. 18.
백준 2535 아시아 정보올림피아드 https://www.acmicpc.net/problem/2535 2535번: 아시아 정보올림피아드 첫 번째 줄에는 대회참가 학생 수를 나타내는 N이 주어진다. 단, 3 ≤ N ≤ 100이다. 두 번째 줄부터 N개의 줄에는 각 줄마다 한 학생의 소속 국가 번호, 학생 번호, 그리고 성적이 하나의 빈칸을 사 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 def sol(n,nums): nums.sort(key=lambda x: x[2],reverse=True) nations=[0]*n cnt=0 for i in range(len(nums)): if cnt==3: break if nations[nums[i][0]]!=2: nations[nums[i][0]]+.. 2022. 10. 18.
백준 20124 모르고리즘 회장님 추천 받습니다 https://www.acmicpc.net/problem/20124 20124번: 모르고리즘 회장님 추천 받습니다 국렬이는 모르고리즘 차기 회장을 빠르게 구해야 한다. 안 그러면 대학원 가서도 회장을 해야 하기 때문이다. 그래서 국렬이는 어떻게든 2020년 연세대학교 프로그래밍 경진대회를 열어서 차기 www.acmicpc.net n=int(input()) nums=[] for i in range(n): name, score = input().split() nums.append([name,int(score)]) nums.sort(key=lambda x: (-x[1],x[0])) print(nums[0][0]) 리스트안에 있는 리스트를 정렬하면 되는데 하나는 오름차순, 하나는 내림차순으로 정렬해야할 경우 l.. 2022. 10. 17.