자바

https://www.acmicpc.net/problem/2346 처음 보자마자, 이건 양방향 연결 리스트를 사용하면 되겠구나 라는 생각이 들었다. 코드import java.io.*;import java.util.StringTokenizer;class Balloon { public int index; public int value; public Balloon prev; public Balloon next; public Balloon(int index, int value) { this.index = index; this.value = value; }}public class Main { public static void main(String[] ..
Stack 두개를 이용하여 Queue구현하기 자바 import java.util.Stack; class Queue { Stack inStack; Stack outStack; public Queue() { this.inStack = new Stack(); this.outStack = new Stack(); } public void enqueue(T value) { inStack.add(value); } public T dequeue() { if (!inStack.isEmpty()) { while(!inStack.isEmpty()) { outStack.add(inStack.pop()); } } return outStack.pop(); } @Override public String toString() { re..
Object 모든 클래스의 조상 필드 없이 메소드들만 갖고 있음 모든 클래스들에 상속됨 필요에 따라 오버라이드하여 사용 toString() public String toString() { return getClass().getName() + "@" + Integer.toHexString(hashCode()); } @HotSpotIntrinsicCandidate public final native Class getClass(); public String getName() { String name = this.name; if (name == null) this.name = name = getName0(); return name; } 클래스명과 해시값을 반환 toString을 Override하지 않으면 jav..
급 관심이 생겨서.. & | ^ ~ > & : AND | : OR ^ : XOR ~ : NOT : RIGHT int x = 5; // 0 0 1 0 1 int y = 19; // 1 0 0 1 1 1. & -> AND int x = 5; // 0 0 1 0 1 int y = 19; // 1 0 0 1 1 int x_and_y = 5 & 19; // 0 0 0 0 1 -> 1 양쪽 모두 1인 것들만 1로, 나머지는 0으로 2. | -> OR int x = 5; // 0 0 1 0 1 int y = 19; // 1 0 0 1 1 int x_or_y = 5 | 19; // 1 0 1 1 1 -> 23 값중에 하나만 1이여도 1, 나머지는 0 3. ^ -> XOR int x = 5; // 0 0 1 0 1 in..
https://www.acmicpc.net/problem/1015 1015번: 수열 정렬 P[0], P[1], ...., P[N-1]은 0부터 N-1까지(포함)의 수를 한 번씩 포함하고 있는 수열이다. 수열 P를 길이가 N인 배열 A에 적용하면 길이가 N인 배열 B가 된다. 적용하는 방법은 B[P[i]] = A[i]이다. 배열 A가 주 www.acmicpc.net import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args)throws I..
https://www.acmicpc.net/problem/1012 1012번: 유기농 배추 차세대 영농인 한나는 강원도 고랭지에서 유기농 배추를 재배하기로 하였다. 농약을 쓰지 않고 배추를 재배하려면 배추를 해충으로부터 보호하는 것이 중요하기 때문에, 한나는 해충 방지에 www.acmicpc.net import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static int[] dx= {1, 0, -1, 0}; static int[] dy= {0, 1, 0, -1}; static int[][] arr; public static void main(Str..
솜사탕코튼
'자바' 태그의 글 목록