Python

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같은 경우에 불가능한 입력이지만 정답으로 출력되므로 ..

카테고리 없음

[BOJ/백준] 5074 - When Do We Finish? [python]

문제 링크 5074번: When Do We Finish? For each line of input, produce one line of output containing a single time, also in the format hh:mm, being the end time of the event as a legal 24 hour time. If this time is not on the same day as the start time, the time will be in the format hh:mm +n, www.acmicpc.net 문제 풀이 이 문제는 시작 시간과 소요 시간이 주어지고, 끝나는 시간을 출력하는 문제이다. 먼저, 형식에 맞게 입력값을 받아준 뒤, 시작 시간에 소요 시간을 더해주고, ..

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..

Algorithm/PS

[BOJ/백준] 4922 - Walk Like an Egyptian [python]

문제 링크 4922번: Walk Like an Egyptian Walk Like an Egyptian is an old multi-player board game played by children of the Sahara nomad tribes. Back in the old days, children would collect stones, and number each one of them. A game with N players requires N2 stones. Each player chooses N stones. www.acmicpc.net 문제 풀이 수열의 규칙을 찾기 쉬운 문제였다. n번째 수는 모두 대각선에 위치해 있다. [1, 3, 7, 13] 순으로 수열이 진행됨을 확인할 수 있다. 이 수열..

Algorithm/PS

[BOJ/백준] 4909 - Judging Olympia [python]

문제 링크 4909번: Judging Olympia For years, a group of Regional Contest Directors (RCDs) of the ACM International Collegiate Programming Contest (ICPC) have been unsatisfied with the way contest submissions get ranked. The group sees it is academically wrong to emphasize the importance of www.acmicpc.net 문제 풀이 6개의 점수 중 최댓값과 최솟값을 뺀 4개의 수의 평균을 구해 출력해주는 문제이다. 단, 출력값에는 불필요한 0이 포함되지 않아야한다. 따라서, 자연수일 경우는 ..

Algorithm/PS

[BOJ/백준] 4892 - 숫자 맞추기 게임 [python]

문제 링크 4892번: 숫자 맞추기 게임 입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있고, n0으로 이루어져 있다. (0 < n0 < 1,000,000) 입력의 마지막 줄에는 0이 하나 주어진다. www.acmicpc.net 문제 풀이 입력값을 받은 뒤, 주어진 규칙에 따라 출력해준다. n1의 홀짝 판단에 따라 출력이 달라진다. 정답 코드 cnt = 1 while True : n = int(input()) if n == 0 : break if n * 3 % 2 == 0 : print("{:d}. even {:d}".format(cnt, (3 * n // 2) * 3 // 9)) else : print("{:d}. odd {:d}".format(cnt, ((3 ..

Algorithm/PS

[BOJ/백준] 4880 - 다음수 [python]

문제 링크 4880번: 다음수 입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 수열의 연속하는 세 정수 a1, a2, a3이 한 줄에 주어진다. (-10,000 < a1, a2, a3 < 10,000) a1, a2, a3은 서로 같지 않다. 입력의 마지막 www.acmicpc.net 문제 풀이 주어진 입력값으로 등차수열 혹은 등비수열을 판단한 뒤, 네 번째에 올 수를 구한다. 등차수열인지 판단한 뒤, 맞지 않으면 등비수열이므로 쉽게 판단할 수 있다. 정답 코드 while True : a_lst = list(map(int, input().split())) if a_lst[0] == a_lst[1] == a_lst[2] == 0 : break if a_lst[2] - a_lst[1] =..

chanwoong1
'Python' 태그의 글 목록 (13 Page)