전체 글 952

[programmers] 특이한 정렬

문제https://school.programmers.co.kr/learn/courses/30/lessons/120880 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int[] solution(int[] numlist, int n) { int[] answer = new int[numlist.length]; ArrayList list = new ArrayList(); for (int i = 0; i () { @Override public int compare(Integer o1, Integer o2) {..

[programmers] 연속된 수의 합

문제https://school.programmers.co.kr/learn/courses/30/lessons/120923 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public int[] solution(int num, int total) { int[] answer = new int[num]; int start = -100, end = -100 + num; int sum = 0; for (int i = start; i 시작을 -100으로 하여 num개의 연속된 수를 더한다. 맨 앞의 값을 빼고, 뒤에 값을 추가해 주는 방식으로 합이 total과 같..

[programmers] 다음에 올 숫자

문제https://school.programmers.co.kr/learn/courses/30/lessons/120924 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public int solution(int[] common) { int answer = 0; int d = common[1] - common[0]; double r = (double) common[1] / common[0]; if (common[1] + d == common[2]) { answer = common[common.length - 1] + d; } else { answ..

[programmers] 컨트롤 제트

문제https://school.programmers.co.kr/learn/courses/30/lessons/120853 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public int solution(String s) { int answer = 0; String arr[] = s.split(" "); int before = 0; for (int i = 0; i 배열에 문자열을 공백 기준으로 나눈 값을 저장한다. 배열을 순회하며 Z라면 이전 값을 빼고, Z가 아니라면 값을 더한다. 출처: 프로그래머스 코딩 테스트 연습, https://school.p..

[programmers] 문자열 계산하기

문제https://school.programmers.co.kr/learn/courses/30/lessons/120902 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public int solution(String my_string) { String arr[] = my_string.split(" "); int answer = Integer.parseInt(arr[0]); for (int i = 1; i my_string을 공백 기준으로 split 한 후 arr에 저장한다. arr에서 연산자만 순회하며 +인 경우는 뒤에 값을 더해주고, -인 경우에는 뒤..

[programmers] 로그인 성공?

문제https://school.programmers.co.kr/learn/courses/30/lessons/120883 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public String solution(String[] id_pw, String[][] db) { String answer = "fail"; for (int i = 0; i answer을 fail로 초기화한다. db를 순회하며 아이디가 일치하는지 확인한다. 아이디가 일치하고 비밀번호가 일치한다면 "login"을 저장하고, 비밀번호가 일치하지 않다면 "wrong pw"를 저장한다. 최종 a..

[programmers] 등수 매기기

문제https://school.programmers.co.kr/learn/courses/30/lessons/120882 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public class Info { double avg; int idx; public Info(double avg, int idx) { this.avg = avg; this.idx = idx; } } public int[] solution(int[][] score) { int[] answer = new int[score.length]; Arra..

[programmers] 다항식 더하기

문제https://school.programmers.co.kr/learn/courses/30/lessons/120863 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public String solution(String polynomial) { String answer = ""; String[] arr = polynomial.split(" "); int x = 0, y = 0; for (int i = 0; i 0) { if (x > 1) { answer += Integer.toString(x); } answer += "x"; } ..

[programmers] 최빈값 구하기

문제https://school.programmers.co.kr/learn/courses/30/lessons/120812 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)import java.util.*;class Solution { public int solution(int[] array) { int answer = 0; HashMap map = new HashMap(); for (int i = 0; i list = new ArrayList(map.keySet()); Collections.sort(list, new Comparator() { @Override public i..

[programmers] OX퀴즈

문제https://school.programmers.co.kr/learn/courses/30/lessons/120907 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 풀이 (Java)class Solution { public String[] solution(String[] quiz) { String[] answer = new String[quiz.length]; for (int i = 0; i quiz를 순회하며 다음 과정을 반복한다. 1. 수식을 공백 기준으로 split 하여 배열 arr에 저장한다.2. 연산자에 맞게 계산한 뒤 수식이 옳다면 O를, 틀리다면 X를 저장한다. 최종 answer을 반..