분류 전체보기
-
79. 나이순 정렬Problem Solving 2023. 1. 15. 18:04
https://www.acmicpc.net/problem/10814 10814번: 나이순 정렬 온라인 저지에 가입한 사람들의 나이와 이름이 가입한 순서대로 주어진다. 이때, 회원들을 나이가 증가하는 순으로, 나이가 같으면 먼저 가입한 사람이 앞에 오는 순서로 정렬하는 프로그램을 www.acmicpc.net 나이와 이름을 한 줄에 하나씩 입력받고 나이 순으로만 정렬하기 (나이가 같을 경우 이름 순 정렬은 하면 안 됨) N = int(input()) members = [] for i in range(N): age, name = input().split() members.append([int(age), name]) members.sort(key=lambda x:x[0]) for i, j in members: ..
-
78. N번째 큰 수Problem Solving 2023. 1. 15. 04:49
https://www.acmicpc.net/problem/2693 2693번: N번째 큰 수 첫째 줄에 테스트 케이스의 개수 T(1 ≤ T ≤ 1,000)가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있고, 배열 A의 원소 10개가 공백으로 구분되어 주어진다. 이 원소는 1보다 크거나 같고, 1,000 www.acmicpc.net 리스트에서 3번째로 큰 수를 구하는 문제 T = int(input()) for i in range(T): li = list(map(int, input().split())) li = sorted(li, reverse=True) print(li[2]) 제한 조건(array마다 원소 개수가 10개로 정해져 있다거나 무조건 3번째로 큰 수를 구한다거나)이 다수 있어서 더 쉬웠던 듯
-
77. Majority ElementProblem Solving 2023. 1. 15. 04:40
https://leetcode.com/problems/majority-element/ Majority Element - LeetCode Majority Element - Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array. Example 1: Input: nums = [3 leetcode.com array에서 "대다수"를 차지하는 숫자를 구하는 문제 class Solution: def majority..
-
76. K번째 수Problem Solving 2023. 1. 15. 04:33
https://school.programmers.co.kr/learn/courses/30/lessons/42748 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 숫자 array와 i, j, k를 받아 array[i:j+1]의 k번째 수를 구하는 문제 def solution(array, commands): answer = [] for comm in commands: newlist = array[comm[0]-1:comm[1]] newlist = sorted(newlist) answer.append(newlist[comm[2] - 1]) return answ..
-
75. 점수 계산Problem Solving 2023. 1. 15. 04:23
https://www.acmicpc.net/problem/2822 2822번: 점수 계산 8개 줄에 걸쳐서 각 문제에 대한 참가자의 점수가 주어진다. 점수는 0보다 크거나 같고, 150보다 작거나 같다. 모든 문제에 대한 점수는 서로 다르다. 입력으로 주어지는 순서대로 1번 문제, 2번 문 www.acmicpc.net 8개 숫자 중 top5를 선택해 더한 값과, 그 top5가 몇 번째인지 위치를 구하는 문제 li = [] for i in range(8): li.append([int(input()), i]) li = sorted(li, reverse=True) ans = 0 ans2 = [] for i in range(5): ans = ans + li[i][0] ans2.append(li[i][1] + 1..
-
74. Valid PalindromeProblem Solving 2023. 1. 15. 00:03
https://leetcode.com/problems/valid-palindrome/ Valid Palindrome - LeetCode Valid Palindrome - A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers. Given a leetcode.com input에서 숫자와 알파벳만을 남긴 후 팔린드롬인지 확인하는 문제 class Solution..
-
73. Fizz BuzzProblem Solving 2023. 1. 14. 19:59
https://leetcode.com/problems/fizz-buzz/ Fizz Buzz - LeetCode Fizz Buzz - Given an integer n, return a string array answer (1-indexed) where: * answer[i] == "FizzBuzz" if i is divisible by 3 and 5. * answer[i] == "Fizz" if i is divisible by 3. * answer[i] == "Buzz" if i is divisible by 5. * answer[i] == i (as a strin leetcode.com 3 6 9 게임 같은 문제 특정 수의 배수일 때 특정한 단어를, 아니면 숫자를 반환하는 문제 class Solution..
-
72. Day of the YearProblem Solving 2023. 1. 14. 19:51
https://leetcode.com/problems/day-of-the-year/ Day of the Year - LeetCode Day of the Year - Given a string date representing a Gregorian calendar [https://en.wikipedia.org/wiki/Gregorian_calendar] date formatted as YYYY-MM-DD, return the day number of the year. Example 1: Input: date = "2019-01-09" Output: 9 Explanation: Give leetcode.com YYYY-MM-DD를 입력받고 그 해의 몇 번째 날인지 찾기 class Solution: def day..