본문 바로가기

Algorithm & SQL179

프로그래머스 JAVA <두 개 뽑아서 더하기> 두 개 뽑아서 더하기 문제 설명 정수 배열 numbers가 주어집니다. numbers에서 서로 다른 인덱스에 있는 두 개의 수를 뽑아 더해서 만들 수 있는 모든 수를 배열에 오름차순으로 담아 return 하도록 solution 함수를 완성해주세요. 제한사항 numbers의 길이는 2 이상 100 이하입니다. numbers의 모든 수는 0 이상 100 이하입니다. 입출력 예numbersresult [2,1,3,4,1] [2,3,4,5,6,7] [5,0,2,7] [2,5,7,9,12] 입출력 예 설명 입출력 예 #1 2 = 1 + 1 입니다. (1이 numbers에 두 개 있습니다.) 3 = 2 + 1 입니다. 4 = 1 + 3 입니다. 5 = 1 + 4 = 2 + 3 입니다. 6 = 2 + 4 입니다. 7.. 2022. 6. 10.
Average Population of Each Continent - BASIC JOIN 제목 그대로 각 지역의 인구 평균을 구하는 문제이다. avg 평균을 이용해야하며, floor를 이용해야 한다 - > 소수점 자리 버림. 또한 group by를 이용해서 그룹을 지어줘야한다 -> 문제 : 모든 대륙의 이름(COUNTRY.Continent)과 각 대륙의 평균 도시 인구(CITY.Population)를 가장 가까운 정수로 내림하여 쿼리합니다. Given the CITY and COUNTRY tables, query the names of all the continents (COUNTRY.Continent) and their respective average city populations (CITY.Population) rounded down to the nearest integer. Note:.. 2022. 6. 9.
African Cities - BASIC JOIN 이전 문제와 푸는 방법은 비슷하다. 혼자 복습할 수 있는 문제였다. 문제를 풀때, 테이블이 어떤 key로 이어져있는지 확인하고 inner join 을 이용해서 country의 continent 값이 africa 인 city 이름을 모두 출력하면 되는 문제였다. Given the CITY and COUNTRY tables, query the names of all cities where the CONTINENT is 'Africa'. Note: CITY.CountryCode and COUNTRY.Code are matching key columns. Input Format The CITY and COUNTRY tables are described as follows: 정답 : select city.name.. 2022. 6. 9.
Population Census - BASIC JOIN SQL join 문을 문제를 풀면서 연습하고 싶어서 join 문제를 풀어보았다. city 테이블과 country 테이블이 2개 존재하며, continent 가 asia 인 인구수를 구하는 문제이다. join할 수 있는 key는 city 테이블의 countrycode 와 country 의 code 이다. Given the CITY and COUNTRY tables, query the sum of the populations of all cities where the CONTINENT is 'Asia'. Note: CITY.CountryCode and COUNTRY.Code are matching key columns. Input Format The CITY and COUNTRY tables are desc.. 2022. 6. 9.
Weather Observation Station 10 city 이름의 끝 자리가 모음으로 끝나지 않은 city를 출력하는 문제이다. 정규식을 이용해야하며, contain duplicates -> 중복 또한 제거해줘야한다. 정답 : select distinct city from station where city regexp '[^aeiou]$' 2022. 6. 9.
Weather Observation Station 9 모음으로 시작하지 않는 단어의 city 이름을 출력하는 문제이다. NOT 과 정규식을 사용했다. 한번더풀기 : select distinct city from station where city not regexp '^[aeiou]' 정답 : select distinct city from station where city not regexp '^[aeiou]' 2022. 6. 8.
Weather Observation Station 8 (regexp 사용) 시작글자와 끝 글자가 a,e,i,o,u 로 되어있는 city 이름을 출력하는 문제이다 다른 블로그를 보니 정규식으로 풀면 더 간단하게 풀 수 있는걸 봐서, 참고해서 풀었다. regexp'^[ 특정문자 ]' => 특정문자로 시작할 때 사용 regexp'[ 특정문자 ]$' => 특정문자로 끝날 때 사용 정답 : select city from station where city regexp '^[aeiou]' and city regexp '[aeiou]$'; 2022. 6. 7.
Weather Observation Station 7 a,e,i,o,u 로 끝나는 city 를 출력하는 문제이고, 추가로 중복없이 출력해야한다. 정답 : select distinct city from station where (city like '%a' or city like '%e' or city like '%i' or city like '%o' or city like '%u'); 2022. 6. 7.
Weather Observation Station 6 (regexp) a e i o u 로 시작하는 city이름을 찾는 문제이다. 찾는 방법이 2가지가 있었다. like로 하나하나 찾아서 출력하는 방법과 regexp 를 사용하는 방법이다. Matching Pattern기능예시설명 . 문자 하나 "..." 문자열의 길이가 세 글자 이상인 것을 찾음. I(수직선) 또는 (OR). I(수직선)로 구분된 문자에 해당하는 문자열을 찾음. "데이터I(수직선)데이타" ‘데이터’ 또는 ‘데이타’에 해당하는 문자열을 찾음. [] [] 안에 나열된 패턴에 해당하는 문자열을 찾음. "[123]d" 대상 문자열에서 ‘1d’ 또는 ‘2d’ 또는 ‘3d’인 문자열을 찾음. ^ 시작하는 문자열을 찾음. "^안녕" 대상 문자열에서 ‘안녕’으로 시작하는 문자열을 찾음. $ 끝나는 문자열을 찾음. "잘가.. 2022. 6. 7.