목록자바 (22)
천천히 빛나는
본 포스팅에서는 [Z, 드래곤커브, 외판원순회, 월드컵, 야구공, 빵집]을 다룹니다. 1074. (실버 1) Z import java.io.*; import java.util.*; public class Main { static int N, r, c, sz, ans; static int map[][]; static boolean success; static void makeZ(int x, int y, int size) { if (size == 1) return; if (x (size / 2) - 1) { // 오..
본 포스팅에서는 [이차원 배열과 연산, 요세푸스 문제, 안전영역, 배열돌리기3, 신기한 소수]을 다룹니다. 17140. (골드4) 이차원 배열과 연산 import java.io.*; import java.util.*; public class Main { static int r, c, k; static int map[][]; static int time; static int freq[]; static ArrayList list = new ArrayList(); static int maxRow, maxCol; static int tempMaxRow, tempmaxCol; static class Pair { int freq; int val; Pair(int freq, int val) { this.freq = ..
본 포스팅에서는 [활주로, 홈 방법서비스, 등산로 조성, 벌꿀채취]를 다룹니다. 4014. (모의 SW) 활주로 import java.io.*; import java.util.*; public class Solution { // 활주로는 높이가 동일한 구간에서 건설 // 높이가 다른 경우 경사로를 설치 static int N, X; // 맵크기, 경사로 높이 static int map[][]; static boolean visited[][]; static int ans; static StringBuilder sb = new StringBuilder(); // 건설 static void construction() { visited = new boolean[N][N]; boolean success; // 가..
이번 포스팅에서는 [Ladder1, 달팽이 숫자, 파리퇴치]를 다룹니다 1210. Ladder1 import java.io.*; import java.util.*; public class Solution { static int[] dx = { 1, 0, 0 }; static int[] dy = { 0, -1, 1 }; static int[][] map = new int[100][100]; static boolean[][] visited; static class Pair { int first; int second; Pair(int first, int second) { this.first = first; this.second = second; } } static boolean ladder(int r, int..
Day 1에서는 [연구소, 연산자 끼워넣기, 감시, 스타트와 링크, 치킨배달, 톱니바퀴, 인구이동, 퇴사]를 다룹니다. 14502. (골드4) 연구소 import java.io.*; import java.util.*; class Pair{ int first; int second; public Pair(int first, int second) { this.first = first; this.second = second; } public int first() { return first; } public int second() { return second; } } public class Main { static int N, M; static int[][] map = new int[8][8]; static fi..
Day 1에서는 [원재의 메모리 복구하기, 농작물 수확하기]를 다룹니다. 1289. 원재의 메모리 복구하기 (D3) import java.io.*; class Solution { static int initCount(String m) { int cnt = m.charAt(0) - '0'; for(int i = 0; i < m.length()-1; i++) { if(m.charAt(i) != m.charAt(i+1)) cnt++; } return cnt; } public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBu..
ArrayList import java.util.ArrayList; public class ArrayListDemo { public static void main(String[] args) { ArrayList al = new ArrayList(); // Object 타입 al.add("one"); // 넣은건 String이지만 Object 타입으로 저장이 되어짐 => String이 아님! al.add("two"); al.add("three"); } } 연관된 데이터를 관리하는 배열 -> 배열의 크기를 변경할 수 없음 이러한 문제를 해결할 수 있는 것을 Collections Framework가 제공하게 된다. 이 중 ArrayList가 Collections Framework의 기능 중 하나이다. for(..
다형성 (Polymorphism) class A{ public String x(){return "x";} } class B extends A{ public String y(){return "y";} } public class PolymorphismDemo1 { public static void main(String[] args) { A obj = new B(); obj.x(); obj.y(); // 오류 발생 } } 부모 클래스 A, 자식 클래스 B가 있을 때 클래스 B의 객체를 A에 담을 수가 있다. 하지만 클래스 B의 메소드 y를 실행할 수는 없다. 클래스 B의 데이터 형을 클래스 A로 하면 클래스 B는 마치 클래스 A인것처럼 동작하게 된다. class A{ public String x(){retur..
인터페이스 (interface) interface I { public void z(); } public class interfaceTest implements I{ public void z(){}; } 어떤 객체가 있고 그 객체가 특정한 인터페이스를 사용한다면 그 객체는 반드시 인터페이스의 메소드들을 구현해야 한다. interface에 명시 되어 있는대로 클래스의 멤버를 구현해야 컴파일이 된다. public interface Calculatable { public void setOprands(int first, int second, int third) ; public int sum(); public int avg(); } // 개발자 A class Calculator implements Calculata..
접근 제어자 class A{ public String y(){ return "public void y()"; } private String z(){ return "private void z()"; } public String x(){ return z(); } } public class AccessDemo1 { public static void main(String[] args) { A a = new A(); System.out.println(a.y()); System.out.println(a.z()); // 호출불가 System.out.println(a.x()); } } 접근 제어자는 클래스의 멤버(변수와 메소드)들의 접근 권한을 지정한다. 객체를 보호하기 위해서 외부의 접근을 허용하거나 차단해야할 필요..