본문 바로가기

python-algorithm1422

Hacker rank Caesar Cipher https://www.hackerrank.com/challenges/caesar-cipher-1 Caesar Cipher | HackerRank Encrypt a string by rotating the alphabets by a fixed value in the string. www.hackerrank.com 1 2 3 4 5 6 7 8 9 10 11 12 def caesarCipher(s, k): # Write your code here answer = '' k = k% 26 for i in s: if i.isalpha(): if ord(i)+k>122 or (ord(i)90) : i = chr(ord(i) + k-26) else: i = chr(ord(i) + k) answer+=i return(a.. 2022. 11. 10.
백준 1969 DNA https://www.acmicpc.net/problem/1969 1969번: DNA DNA란 어떤 유전물질을 구성하는 분자이다. 이 DNA는 서로 다른 4가지의 뉴클레오티드로 이루어져 있다(Adenine, Thymine, Guanine, Cytosine). 우리는 어떤 DNA의 물질을 표현할 때, 이 DNA를 이루는 뉴클레오 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 from collections import Counter def cal_hamming(dna,target): hamming = 0 for compared_dna in dna: for i in range(len(target)): if compared_dna[i.. 2022. 11. 10.
백준 11576 Base Conversion https://www.acmicpc.net/problem/11576 11576번: Base Conversion 타임머신을 개발하는 정이는 오랜 노력 끝에 타임머신을 개발하는데 성공하였다. 미래가 궁금한 정이는 자신이 개발한 타임머신을 이용하여 500년 후의 세계로 여행을 떠나게 되었다. 500년 후의 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 if __name__ == '__main__': a,b=map(int,input().split()) m=int(input()) original_number=0 future_number=list(map(int,input().split())) for i in range(m): tmp_num=future_number[i] or.. 2022. 11. 10.
백준 18258 큐 2 https://www.acmicpc.net/problem/18258 18258번: 큐 2 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 2,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 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 import sys from collections import deque n=int(input()) commands=deque() for i in range(n): command = sys.stdin.readline().. 2022. 11. 9.
백준 1620 나는야 포켓몬 마스터 이다솜 https://www.acmicpc.net/problem/1620 1620번: 나는야 포켓몬 마스터 이다솜 첫째 줄에는 도감에 수록되어 있는 포켓몬의 개수 N이랑 내가 맞춰야 하는 문제의 개수 M이 주어져. N과 M은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수인데, 자연수가 뭔지는 알지? 모르면 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 import sys n , m =map(int,sys.stdin.readline().split()) pokemon = dict() for i in range(1,n+1): name = sys.stdin.readline().rstrip() pokemon[name] = i pokemon_reversed = dict(ma.. 2022. 11. 9.
백준 4949 균형잡힌 세상 https://www.acmicpc.net/problem/4949 4949번: 균형잡힌 세상 하나 또는 여러줄에 걸쳐서 문자열이 주어진다. 각 문자열은 영문 알파벳, 공백, 소괄호("( )") 대괄호("[ ]")등으로 이루어져 있으며, 길이는 100글자보다 작거나 같다. 각 줄은 마침표(".")로 끝난다 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 while True: answer = 'yes' s=input() if s=='.': break stack=[] for i in s: if i=='(' or i=='[': stack.append(i) if i==')': if len(stack) != 0 and stack.. 2022. 11. 9.
백준 18398 HOMWRK https://www.acmicpc.net/problem/18398 18398번: HOMWRK In one of the beautiful cities of Afghanistan two sisters are going to program a simple game to help them solve their mathematics homework. Their homework asks them to calculate the sum and multiplication of two numbers. Your task is to help them to build www.acmicpc.net 1 2 3 4 5 6 t=int(input()) for j in range(t): n=int(input()) for i in ran.. 2022. 11. 9.
백준 1966 프린터 큐 https://www.acmicpc.net/problem/1966 1966번: 프린터 큐 여러분도 알다시피 여러분의 프린터 기기는 여러분이 인쇄하고자 하는 문서를 인쇄 명령을 받은 ‘순서대로’, 즉 먼저 요청된 것을 먼저 인쇄한다. 여러 개의 문서가 쌓인다면 Queue 자료구조에 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 from collections import deque for i in range(int(input())): n, m = map(int, input().split()) waiting= deque(list(map(int,input().split()))) importance = deque(list([i for i in range(n)]).. 2022. 11. 8.
백준 10816 숫자 카드 2 https://www.acmicpc.net/problem/10816 10816번: 숫자 카드 2 첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10, www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import sys from collections import Counter n=int(sys.stdin.readline()) cards=list(map(int, sys.stdin.readline().split())) m=int(sys.stdin.readline()) to_find=list(map(i.. 2022. 11. 8.
백준 11866 요세푸스 문제 0 https://www.acmicpc.net/problem/11866 11866번: 요세푸스 문제 0 첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 1,000) www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 from collections import deque n, k =map(int,input().split()) nums=[i+1 for i in range(n)] nums = deque(nums) answer = [] while nums: for i in range(k-1): nums.append((nums.popleft())) answer.append(nums.popleft()) answer = map(str, answer) p.. 2022. 11. 8.
Hacker rank Super Reduced String 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 def superReducedString(s): # Write your code here my_stack=[] for i in s: if len(my_stack) == 0 or my_stack[-1]!=i: my_stack.append(i) elif my_stack[-1]==i: my_stack.pop() answer = ''.join(my_stack) if answer == '': answer = 'Empty String' return answer if __name__ == '__ma cs https://www.hackerrank.com/challenges/reduced-string/problem Super Reduced String | .. 2022. 11. 8.
백준 18511 큰 수 구성하기 https://www.acmicpc.net/problem/18511 18511번: 큰 수 구성하기 첫째 줄에 N, K의 원소의 개수가 공백을 기준으로 구분되어 자연수로 주어진다. (10 ≤ N ≤ 100,000,000, 1 ≤ K의 원소의 개수 ≤ 3) 둘째 줄에 K의 원소들이 공백을 기준으로 구분되어 주어진다. 각 www.acmicpc.net 1 2 3 4 5 6 7 8 9 10 11 12 13 14 from itertools import product def sol(n,k,nums): for i in range(len(str(n)),-1,-1): prod = list(product(nums, repeat=i)) for j in prod: tmp=''.join(map(str,j)) if n>=int(t.. 2022. 11. 8.