Cute Running Puppy
반응형

algorithm 42

[python] 125. Valid Palindrome

https://leetcode.com/problems/valid-palindrome/ Valid Palindrome - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 주어진 문자열이 펠린드롬인지 확인하는 문제 대소문자를 구분하지 않고, 알파벳과 숫자만을 대상으로 한다. 풀이 1. class Solution: def isPalindrome(self, s: str) -> bool: s = ''.join(char for char in s if char.isalpha(..

algorithm/Leetcode 2022.03.19

[python] 5622_다이얼

https://www.acmicpc.net/problem/5622 5622번: 다이얼 첫째 줄에 알파벳 대문자로 이루어진 단어가 주어진다. 단어의 길이는 2보다 크거나 같고, 15보다 작거나 같다. www.acmicpc.net string = list(input()) dial = { 3: ["A", "B", "C"], 4: ["D", "E", "F"], 5: ["G", "H", "I"], 6: ["J", "K", "L"], 7: ["M", "N", "O"], 8: ["P", "Q", "R", "S"], 9: ["T", "U", "V"], 10: ["W", "X", "Y", "Z"] } res = 0 for i in string: for j in range(3, 11): if i in dial[j]: re..

algorithm/Baekjoon 2022.02.17

[python] 2941_크로아티아 알파벳

https://www.acmicpc.net/problem/2941 2941번: 크로아티아 알파벳 예전에는 운영체제에서 크로아티아 알파벳을 입력할 수가 없었다. 따라서, 다음과 같이 크로아티아 알파벳을 변경해서 입력했다. 크로아티아 알파벳 변경 č c= ć c- dž dz= đ d- lj lj nj nj š s= ž z= www.acmicpc.net cro = ["c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="] alpha = input() for i in cro: if i in alpha: ''' alpha = alpha.replace(i, '') res += 1 발견한 크로아티아 문자를 없애면 중복된 크로아티아 문자를 셀 수 없다. ''' alpha = alpha.r..

algorithm/Baekjoon 2022.02.17

[python] 1712_손익분기점

https://www.acmicpc.net/problem/1712 1712번: 손익분기점 월드전자는 노트북을 제조하고 판매하는 회사이다. 노트북 판매 대수에 상관없이 매년 임대료, 재산세, 보험료, 급여 등 A만원의 고정 비용이 들며, 한 대의 노트북을 생산하는 데에는 재료비와 www.acmicpc.net a, b, c = map(int, input().split()) if (b >= c): res = -1 else: res = int(a / (c - b)) + 1 print(type(round(a / (c - b)))) print(res) 1. b == c 일 때에도 손익분기점이 계산되지 않는다. 2. 계산 결과를 int 형으로 변환하는 것을 잊지 않아야 한다.

algorithm/Baekjoon 2022.02.17

[python] 2292_벌집

https://www.acmicpc.net/problem/2292 2292번: 벌집 위의 그림과 같이 육각형으로 이루어진 벌집이 있다. 그림에서 보는 바와 같이 중앙의 방 1부터 시작해서 이웃하는 방에 돌아가면서 1씩 증가하는 번호를 주소로 매길 수 있다. 숫자 N이 주어졌 www.acmicpc.net num = int(input()) honeycomb = [1] while(1): if (num == 1): break else: honeycomb.append(honeycomb[-1] + (6 * len(honeycomb))) if(honeycomb[-1] >= num): break print(len(honeycomb)) 계차수열의 값들을 계산해서 리스트에 넣고 리스트의 개수를 세는 방식으로 코드를 작성하..

algorithm/Baekjoon 2022.02.17

[python]level1. 키패드 누르기

https://programmers.co.kr/learn/courses/30/lessons/67256 코딩테스트 연습 - 키패드 누르기 [1, 3, 4, 5, 8, 2, 1, 4, 5, 9, 5] "right" "LRLLLRLLRRL" [7, 0, 8, 2, 8, 3, 1, 5, 7, 6, 2] "left" "LRLLRRLLLRR" [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] "right" "LLRLLRLLRL" programmers.co.kr 정답 코드 def solution(numbers, hand): answer = '' key = [[1, 2, 3], [4, 5, 6], [7, 8, 9], ['*', 0, '#']] left = [1, 4, 7, '*'] right = [3, 6, 9,..

[python] 백준 2908_상수

https://www.acmicpc.net/problem/2908 2908번: 상수 상근이의 동생 상수는 수학을 정말 못한다. 상수는 숫자를 읽는데 문제가 있다. 이렇게 수학을 못하는 상수를 위해서 상근이는 수의 크기를 비교하는 문제를 내주었다. 상근이는 세 자리 수 두 www.acmicpc.net a, b = list(input().split()) new_a = [] new_b = [] for i in a: new_a.insert(0, i) for i in b: new_b.insert(0, i) new_a = ''.join(new_a) new_b = ''.join(new_b) print(max(new_a, new_b))

algorithm/Baekjoon 2021.08.05

[python] 백준 1152_단어의 개수

https://www.acmicpc.net/problem/1152 1152번: 단어의 개수 첫 줄에 영어 대소문자와 띄어쓰기로 이루어진 문자열이 주어진다. 이 문자열의 길이는 1,000,000을 넘지 않는다. 단어는 띄어쓰기 한 개로 구분되며, 공백이 연속해서 나오는 경우는 없다. 또한 www.acmicpc.net 정답 코드 s = input().split(' ') cnt = len(s) if (s[0] == ''): cnt -= 1 if (s[len(s) - 1] == ''): cnt -= 1 print(cnt) 예제 출력 문자열 맨 앞과 뒤에 공백이 있음에 주의해야 한다.

algorithm/Baekjoon 2021.08.05

[python] 백준 1157_단어 공부

https://www.acmicpc.net/problem/1157 1157번: 단어 공부 알파벳 대소문자로 된 단어가 주어지면, 이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. 단, 대문자와 소문자를 구분하지 않는다. www.acmicpc.net 정답 코드 #입력 받은 문자를 대문자로 변경하여 s1에 저장한다. s1 = input().upper() #중복을 제거하기 위해 s1을 set 함수에 넣는다. s2 = list(set(s1)) #s1에 등장하는 문자의 개수를 세어 cnt 리스트에 넣는다. cnt = [] for i in s2: cnt.append(s1.count(i)) #index를 활용하여 가장 많이 등장한 알파벳을 변수에 저장한다. max_alphabet = s..

algorithm/Baekjoon 2021.08.04

[python] 백준 2675_문자열 반복

https://www.acmicpc.net/problem/2675 2675번: 문자열 반복 문자열 S를 입력받은 후에, 각 문자를 R번 반복해 새 문자열 P를 만든 후 출력하는 프로그램을 작성하시오. 즉, 첫 번째 문자를 R번 반복하고, 두 번째 문자를 R번 반복하는 식으로 P를 만들면 된다 www.acmicpc.net 정답 코드 1 n = int(input()) for _ in range(n): r, s = input().split() r = int(r) for i in range(len(s)): for j in range(r): print(s[i], end='') print() 정답 코드 2 n = int(input()) for _ in range(n): r, s = input().split() r ..

algorithm/Baekjoon 2021.08.04