Algorithm/PS

Algorithm/PS

[BOJ/백준] 5342 - Billing [python]

문제 링크 5342번: Billing The accounting office is having troubling with billing each department for the supplies purchased last semester. Below is a chart of all the supplies and how much they cost. You must write a program that reads a list of the supplies and computes the total www.acmicpc.net 문제 풀이 각 물건에 해당하는 가격을 저장한 후, 입력값을 받을 때마다 물건의 가격을 더해준다. 출력은 소수점 2번째 자리까지만 출력해준다. 정답 코드 costs = {"Paper" : 5..

Algorithm/PS

[BOJ/백준] 5340 - Secret Location [python]

문제 링크 5340번: Secret Location Someone is waiting at a secret location and has sent a text message with the coordinates of their location. The message contains the latitude and longitude coordinates in degrees, minutes, and seconds. Of course, the message is encoded so you must write a www.acmicpc.net 문제 풀이 이 문제는 총 6줄의 문자열이 주어지는데, 각각의 문자열의 길이를 출력 조건에 맞게 출력해주면 된다. 단, 이 문제가 문자열 중 마지막 문자로 공백이 들어올 수도 ..

Algorithm/PS

[BOJ/백준] 5292 - Counting Swann’s Coins [python]

문제 링크 5292번: Counting Swann’s Coins Governor Weatherby Swann orders you to count the number of coins in the government treasury. To make the job more interesting you decide to say ”Dead” for all numbers that are a multiple of 3 and ”Man” for all numbers that are a multiple of 5. For www.acmicpc.net 문제 풀이 3의 배수이면 "Dead"를 출력하고, 5의 배수를 "Man"을 출력한다. 3의 배수이자 5의 배수라면 "DeadMan"을 출력한다. 그 외의 수일 경우, 출력하고 ..

Algorithm/PS

[프로그래머스] 두 큐 합 같게 만들기 [python]

문제 링크 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 풀이 투포인터에 관한 문제이다. 합계를 미리 계산해두고, 조건에 따라 값을 추가하거나 빼는 형식으로 반복문을 돌려주었다. 이 문제의 제목에서부터 큐를 사용해야한다고 생각이 들겠지만, 사실 사용하지 않아도 된다. 오히려 파이썬에서는 deque를 사용하는 것이 리스트 사용보다 더 안좋을수도 있다. 이 문제를 풀기 위해서 일단, 기본적으로 확인해볼 것은 제한사항이다. 두 queue의 길이가 최장 300000까지 될 수 있다고 하니, 시간복잡도에 대해 조금 더 신경써주어야 한다. 그 외의 사항은 파이..

Algorithm/PS

[BOJ/백준] 5102 - Sarah's Toys [python]

문제 링크 5102번: Sarah's Toys Input will be a number of lines, with each line representing a night in Sarah’s house. Each line will have 2 whole numbers, separated by a space. The first number is how many stuffed toys she owns at the time. The second number is the number of toys left www.acmicpc.net 문제 풀이 몫과 나머지를 조건에 맞게 구해주는 문제이다. 두 입력값 a, b가 주어진다면, 현재 사라가 가지고 있는 장난감의 수는 a - b이다. 따라서 a - b의 값에 따라 출력..

Algorithm/PS

[BOJ/백준] 5101 - Sequences [python]

문제 링크 5101번: Sequences 11 is the 5th term The sequence is –1, -4, -7, -10 (-1+ -3 = -4, -4 + –3 = -7, -7+ -3 = -10) -8 isn’t in the sequence. www.acmicpc.net 문제 풀이 등차 수열의 첫번째 값, 차, 검사할 값이 주어지는데, 검사할 값과 첫번째 값을 빼준 뒤, 차를 나누었을 때 나머지가 0이라면 검사할 값은 등차수열에 포함이 된다. 따라서 첫번째 값, 차, 검사할 값을 각각 a, b, c라고한다면, (c - a) % b == 0이 되는 값을 찾아주면 된다. 단, 주의할 점이 있는데, 나누어 떨어지는 경우만 찾게 되면, 3, 2, 1같은 경우에 불가능한 입력이지만 정답으로 출력되므로 ..

Algorithm/PS

[BOJ/백준] 5073 - 삼각형과 세 변 [python]

문제 링크 5073번: 삼각형과 세 변 각 입력에 맞는 결과 (Equilateral, Isosceles, Scalene, Invalid) 를 출력하시오. www.acmicpc.net 문제 풀이 주어진 조건에 따라 입력값을 분류하는 문제이다. 조건문의 순서가 중요한데, Invaild 검사를 먼저 하고난 뒤, 삼각형의 조건에 맞게 조건문을 작성해주면 된다. 정답 코드 while True : lst = list(map(int, input().split())) if sum(lst) == 0 : break if max(lst) >= sum(lst) - max(lst) : print("Invalid") elif lst[0] == lst[1] == lst[2] : print("Equilateral") elif lst..

Algorithm/PS

[BOJ/백준] 5013 - Death Knight Hero [python]

문제 링크 5013번: Death Knight Hero Output the number of battles our hero won, assuming he won each battle where he did not Chains of Ice immediately followed by Death Grip. www.acmicpc.net 문제 풀이 이 문제는 주어진 입력값에 "C"와 "D"가 연속으로 존재한다면 패배로 간주한다. 승리한 전투의 수를 구하는 문제이다. 문자열을 검사할 때, "C"와 "D"가 연속으로 위치하는지 검사하면 된다. 정답 코드 cnt = 0 for _ in range(int(input())) : s = input() win = True for i in range(1, len(s)) : if..

chanwoong1
'Algorithm/PS' 카테고리의 글 목록 (12 Page)