PS
-
Level1) 가운데 글자 가져오기PS/programmers 2020. 9. 8. 14:41
class Solution { public static String solution(String s) { String answer = ""; if (s.length()%2 != 0) { answer += s.charAt(s.length()/2); } else { answer += s.charAt(s.length()/2 - 1); answer += s.charAt(s.length()/2); } return answer; } } - charAt으로 그 부분을 빼서 더해줬다. return s.substring((s.length()-1) / 2, s.length()/2 + 1); - 다른 풀이 코드 - 훨씬 간편하게 했는데 나는 이렇게 생각 못할거같다 ,,, - 내가 떠올릴 수 있는 방법으로 해보자
-
Level1) 2016년PS/programmers 2020. 9. 8. 14:19
class Solution { public static String solution(int a, int b) { int[] days = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; String[] day_week = { "THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED" }; int totalDays = 0; if (a == 1) { totalDays = b; } else { for (int i = 0; i < a-1; i++) { totalDays += days[i]; } totalDays += b; } return day_week[totalDays%7]; } } - 적다보니까 규칙이 보여서 월마다의 일수배열, 요일배열 ..
-
Level1) K번째 수PS/programmers 2020. 9. 8. 13:06
import java.util.ArrayList; import java.util.Arrays; class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; ArrayList list = new ArrayList(); for (int c = 0; c < commands.length; c++) { int i = commands[c][0]; int j = commands[c][1]; int k = commands[c][2]; int[] arr = Arrays.copyOfRange(array, i - 1, j); Arrays.sort(arr); answer[c] = arr..
-
Level1) 모의고사PS/programmers 2020. 9. 8. 12:43
import java.util.ArrayList; import java.util.Arrays; class Solution { public static int[] solution(int[] answers) { int[] student1 = {1, 2, 3, 4, 5}; int[] student2 = {2, 1, 2, 3, 2, 4, 2, 5}; int[] student3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; int[] cnt = new int[3]; for (int i = 0; i < answers.length; i++) { if (answers[i] == student1[i%5]) { cnt[0]++; } if (answers[i] == student2[i%8]) { cnt[1]+..
-
boj)2644 - 촌수계산PS/boj 2020. 9. 5. 16:40
import java.io.*; import java.util.*; public class Main { static int N, M, person1, person2, x, y; static LinkedList[] nodeList; static boolean[] visited; static boolean check; static class Node { int index; int distance; public Node(int index, int distance) { this.index = index; this.distance = distance; } } public static void bfs(int start, int end) { Queue q = new LinkedList(); q.offer(new No..
-
boj)7576 - 토마토PS/boj 2020. 9. 5. 14:30
import java.io.*; import java.util.*; public class Main { static int N, M; static int[][] graph; static int[] dx = {-1, 1, 0, 0}; static int[] dy = {0, 0, -1, 1}; // x,y 좌표가 함께 움직야하고, 날짜를 세야하는데 그걸 클래스 안에 넣었음 static class Dot { int x; int y; int day; public Dot(int x, int y, int day) { this.x = x; this.y = y; this.day = day; } } public static void main(String[] args) throws IOException { input();..
-
boj)2178 - 미로 탐색PS/boj 2020. 9. 3. 18:20
import java.io.*; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; class Node { int index; int distance; public Node(int index, int distance) { this.index = index; this.distance = distance; } public int getIndex() { return index; } public int getDistance() { return distance; } } public class Main { static int n, m, nx, ny; static int[][] graph = new int[101]..