본문 바로가기

Programmers

(188)
문자열 밀기 1234567891011121314151617181920212223242526import java.util.*; class Solution { public int solution(String A, String B) { int answer = 0; List AList = new LinkedList(); for(char ch : A.toCharArray()) AList.add(ch); int cnt = 0; for(int i=0;i
주문량이 많은 아이스크림들 조회하기 1 2 3 4 5 6 7 8 9 select f.flavor from first_half f join (select flavor, sum(total_order) tSum from july group by flavor) j on f.flavor = j.flavor order by (f.total_order + j.tSum) desc limit 3 Colored by Color Scripter cs 1. 7월의 총 주문량을 계산한다. 2. 상반기 총 주문량과 flavor를 기준으로 join한다. 3. 두 주문량을 합하여, 내림차순 정렬한다.
오랜 기간 보호한 동물(2) 1 2 3 4 5 6 select i.animal_id, i.name from animal_ins i inner join animal_outs o on i.animal_id = o.animal_id where o.datetime - i.datetime >= 0 order by o.datetime - i.datetime desc limit 2; Colored by Color Scripter cs 1. join을 이용하여 입양 간 동물에 대해서만 검사한다. 2. 입양 간 날짜 - 보호한 날짜가 0이상인 정상적인 데이터를 필터링한다. 3. 내림차순으로 정렬한다. 4. 출력한다.
오랜 기간 보호한 동물(1) 1 2 3 4 select name, datetime from animal_ins where animal_id not in (select animal_id from animal_outs) order by datetime limit 3; Colored by Color Scripter cs 1. 입양 간 동물을 불러온다. 2. not in을 이용하여 보호소에 있는 동물 중 입양 간 동물들의 아이디에 포함되지 않은 아이디를 검색한다. 3. 정렬 후 출력
없어진 기록 찾기 1 select animal_id, name from animal_outs where animal_id not in (select animal_id from animal_ins); cs not in을 사용하여 간단히 해결하였다.
다단계 칫솔 판매 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import java.util.*;class Solution { static HashMap map = new HashMap(); static ArrayList list = new ArrayList(); static void moneyCal(String seller, int money) { Persons person = list.get(map.get(seller)); int remain = (int) (money * 0.1); person.profit += money - remain; // 추천인이 없거나 배분 금액이 없을 경우 종료 if(person.re..
네트워크 1234567891011121314151617181920212223242526class Solution { static boolean visited[]; public static void DFS(int pos, int n, int[][] computers) { if(visited[pos]) return; visited[pos] = true; for(int i=0;i
헤비 유저가 소유한 장소 1 2 select id, name, host_id from places where host_id in (select host_id from places group by host_id having count(*) >= 2) order by id; cs 서브쿼리를 사용하는 문제이다.