본문 바로가기

알고리즘

(27)
백준 14503 - 로봇 청소기 (Python) https://www.acmicpc.net/problem/14503 문제  풀이# 방의 크기n,m = map(int,input().split())# 로봇 청소기가 있는 방의 좌표(r,c)와 로봇청소기가 바라보는 방향(d)r,c,d = map(int,input().split())# d = 0 (북), 1(동), 2(남), 3(서)room = []for i in range(n): room_num = list(map(int,input().split())) room.append(room_num)# 4방향을 체크한다. (청소할 구역이 있는지 없는지)def check4can(r,c,room): cnt = 0 # 먼저 r,c가 최상단 (0,0), 최하단 (n-1,m-1)에 있을 때를 배제 ..
프로그래머스 - H-Index 문제https://school.programmers.co.kr/learn/courses/30/lessons/42747# 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr  풀이def solution(citations): citations.sort() answer = 0 for i in range(citations[-1]): cnt = 0 for j in range(len(citations)): if citations[j] >= i: cnt = j ..
프로그래머스 - 가장 큰 수 문제https://school.programmers.co.kr/learn/courses/30/lessons/42746 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr 풀이def solution(numbers): numbers = list(map(str,numbers)) numbers.sort(key=lambda x:x*3, reverse = True) return str(int(''.join(numbers)))  일반적인 방법으로는 풀기가 힘들다.. 내림차순의 방법으로 푼다고 생각하면 [3,30,34]가 있을 때, [34,30,3..
프로그래머스 - K번째 수 문제https://school.programmers.co.kr/learn/courses/30/lessons/42748 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr  풀이def solution(array, commands): answer = [] for i in commands: temp = array[i[0]-1:i[1]] temp.sort() answer.append(temp[i[2]-1]) return answer
프로그래머스 - 크레인 인형뽑기 게임 문제2019 카카오 개발자 겨울 인텁십 Lv1 - 크레인 인형뽑기 게임https://school.programmers.co.kr/learn/courses/30/lessons/64061 프로그래머스코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.programmers.co.kr  풀이def solution(board, moves): list = [] answer = 0 for i in moves: for j in range(len(board)): if board[j][i-1] != 0: if len(list) > 0 and ..
백준 11478 - 서로 다른 부분 문자열의 개수 문제https://www.acmicpc.net/problem/11478     풀이# 백준 / 실버3 / 서로 다른 부분 문자열의 개수string = input()list = []for i in range(len(string)): for j in range(len(string)): if ((j+i)+1) > len(string): break list.append(string[j:(j+i)+1]) print(len(set(list)))
백준 2003 - 수들의 합 2 문제https://www.acmicpc.net/problem/2003   풀이# 백준 / 실버4 / 수들의 합2n,m = map(int,input().split())nums = list(map(int,input().split()))answer = 0for i in range(len(nums)): sum = 0 for j in range(i,len(nums)): sum += nums[j] if sum == m: answer += 1 break elif sum > m: break print(answer)
백준 1748 - 수 이어 쓰기 1 문제https://www.acmicpc.net/problem/1748  풀이# 백준 / 실버4 / 수 이어 쓰기 1n = int(input())if n // 10 == 0: print(n)elif n // 100 == 0: print(2*(n-9) + 9)elif n // 1000 == 0: print(3*(n-99) + 189)elif n // 10000 == 0: print(4*(n-999) + 2889)elif n // 100000 == 0: print(5*(n-9999) + 38889)elif n // 1000000 == 0: print(6*(n-99999) + 488889)elif n // 10000000 == 0: print(7*(n-999999) + 58..