LIFO???
add(), offer()
get(), peek()
Deque ์ธํฐํ์ด์ค์ ๊ตฌํ์ฒด ์ข ๋ฅ : ArrayDeque, LinkedList
LinkedList ํ์ฉ ์ฝ๋
[์๋ฃ๊ตฌ์กฐ] ์๋ฐ ๋ฑ(Deque)์ ํด๋์ค ์ฌ์ฉํ๊ธฐ (tistory.com)
(์๊ฐ ์ด๊ณผ)
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
System.setIn(new FileInputStream("./input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int[] ax = new int[N];
for(int n = 0; n < N; n++)
ax[n] = Integer.parseInt(st.nextToken());
LinkedList<Integer> out = new LinkedList<Integer>();
for(int n = N-1; n >= 0; n--) {
int cur = N - (n); // ํ์ฌ ๊ฐ
if(ax[n] == 1) {
out.addFirst(cur);
} else if(ax[n] == 2) {
if(out.size() < 2) {
out.add(cur);
} else {
out.add(1, cur);
}
} else if(ax[n] == 3) {
out.add(cur);
}
}
for(int n = 0; n < N; n++) {
bw.write(out.get(n) + " ");
}
br.close();
bw.flush();
bw.close();
}
}
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
System.setIn(new FileInputStream("./input.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int[] ax = new int[N];
for(int n = 0; n < N; n++)
ax[n] = Integer.parseInt(st.nextToken());
Deque<Integer> deq = new LinkedList<>();
for(int n = N-1; n >= 0; n--) {
if(ax[n] == 1) {
deq.addFirst(N - (n));
} else if(ax[n] == 2) {
Integer first = deq.pollFirst();
deq.addFirst(N - (n));
if(first != null) {
deq.addFirst(first);
} else if(ax[n] == 3) {
deq.add(N - (n));
}
}
for(int n = 0; n < N; n++) {
bw.write(deq.poll() + " ");
}
br.close();
bw.flush();
bw.close();
}
}
import java.io.BufferedReader; // ์ํฌํธ ํ์
import java.io.BufferedWriter;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String s = br.readLine(); // bufferedwriter ์ ๊ธฐ๋ณธํ์ String
int i = Integer.parseInt(s) +10; // String ์ int๋ก ํ๋ณํ ํ +10 !!
br.close(); // bufferedreader ๋ ์
๋ ฅ์ ๋ง์ณค๋ค๋ฉด ๋ซ์์ฃผ์
bw.write("์
๋ ฅ๋ฐ์ ๊ฐ : "+ s); // ์ถ๋ ฅ
bw.newLine(); // ๊ฐํ ๋ฉ์๋
bw.write("์
๋ ฅ๋ฐ์ ๊ฐ +10 : "+i+"\n"); // ์ด๋ ๊ฒ ํ๋๊น ์ ๋๋ก ์ถ๋ ฅ๋จ
bw.flush(); // ๋จ์ ๊ฐ ์ถ๋ ฅ && ๋ฒํผ ์ด๊ธฐํ
bw.close(); // bufferedwriter ๋ซ๊ธฐ
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // ์
๋ ฅ
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); // ์ถ๋ ฅ
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
for(int i = 0; i < T; i++) {
st = new StringTokenizer(br.readLine());
bw.write((Integer.parseInt(st.nextToken()) + Integer.parseInt(st.nextToken()) + "\n");
}
bw.close();
br.close();
}
[Java] StringTokenizer ๋ฌธ์์ด ๋ถ๋ฆฌํ๊ธฐ (split๊ณผ ์ฐจ์ด๋ ๋ญ๊น?) (tistory.com)
์ข์ ๊ธ ๊ฐ์ฌํฉ๋๋ค. ์์ฃผ ์ฌ๊ฒ์ :)