Skip to content

Commit

Permalink
Merge pull request #174 from 1821-Study/sa11k
Browse files Browse the repository at this point in the history
Feat:Add solution of #118
  • Loading branch information
sa11k authored Jul 29, 2022
2 parents 2f4ef4f + c28be7d commit 9cb7446
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/BaekJoon/sa11k/10816/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.io.*;
import java.util.*;

class Main{

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
Map<Integer, Integer> numCard = new HashMap<>();

int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for(int i = 0; i<N; i++){
int num = Integer.parseInt(st.nextToken());
if(!numCard.containsKey(num)) numCard.put(num, 1);
else numCard.put(num, numCard.get(num) + 1);
}

int M = Integer.parseInt(br.readLine());
st = new StringTokenizer(br.readLine(), " ");
for(int i = 0; i<M; i++){
int num = Integer.parseInt(st.nextToken());
if(!numCard.containsKey(num)) sb.append(0).append(" ");
else sb.append(numCard.get(num)).append(" ");
}

System.out.println(sb);

br.close();
}
}
36 changes: 36 additions & 0 deletions src/BaekJoon/sa11k/10828/Main_220728.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.io.*;
import java.util.*;

class Main_220728 {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
Stack<Integer> stack = new Stack<>();

for(int i = 0; i<N; i++){
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
String command = st.nextToken();
if(command.equals("push")) stack.push(Integer.parseInt(st.nextToken()));
else if(command.equals("pop")){
if (stack.isEmpty()) sb.append(-1).append("\n");
else sb.append(stack.pop()).append("\n");
}
else if (command.equals("size")) sb.append(stack.size()).append("\n");
else if (command.equals("empty")){
if (stack.isEmpty()) sb.append(1).append("\n");
else sb.append(0).append("\n");
}
else if(command.equals("top")){
if (stack.isEmpty()) sb.append(-1).append("\n");
else sb.append(stack.peek()).append("\n");
}
}

System.out.println(sb);


br.close();
}
}
40 changes: 40 additions & 0 deletions src/BaekJoon/sa11k/10845/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import java.io.*;
import java.util.*;

class Main {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
ArrayDeque<Integer> queue = new ArrayDeque<>();

for(int i = 0; i<N; i++){
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
String command = st.nextToken();
if(command.equals("push")) queue.add(Integer.parseInt(st.nextToken()));
else if(command.equals("pop")){
if (queue.isEmpty()) sb.append(-1).append("\n");
else sb.append(queue.poll()).append("\n");
}
else if (command.equals("size")) sb.append(queue.size()).append("\n");
else if (command.equals("empty")){
if (queue.isEmpty()) sb.append(1).append("\n");
else sb.append(0).append("\n");
}
else if(command.equals("front")){
if (queue.isEmpty()) sb.append(-1).append("\n");
else sb.append(queue.peekFirst()).append("\n");
}
else if(command.equals("back")){
if (queue.isEmpty()) sb.append(-1).append("\n");
else sb.append(queue.peekLast()).append("\n");
}
}

System.out.println(sb);


br.close();
}
}
45 changes: 45 additions & 0 deletions src/BaekJoon/sa11k/10866/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.io.*;
import java.util.*;

class Main {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
ArrayDeque<Integer> queue = new ArrayDeque<>();

for(int i = 0; i<N; i++){
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
String command = st.nextToken();
if(command.equals("push_front")) queue.addFirst(Integer.parseInt(st.nextToken()));
else if(command.equals("push_back")) queue.addLast(Integer.parseInt(st.nextToken()));
else if(command.equals("pop_front")){
if (queue.isEmpty()) sb.append(-1).append("\n");
else sb.append(queue.pollFirst()).append("\n");
}
else if(command.equals("pop_back")){
if (queue.isEmpty()) sb.append(-1).append("\n");
else sb.append(queue.pollLast()).append("\n");
}
else if (command.equals("size")) sb.append(queue.size()).append("\n");
else if (command.equals("empty")){
if (queue.isEmpty()) sb.append(1).append("\n");
else sb.append(0).append("\n");
}
else if(command.equals("front")){
if (queue.isEmpty()) sb.append(-1).append("\n");
else sb.append(queue.peekFirst()).append("\n");
}
else if(command.equals("back")){
if (queue.isEmpty()) sb.append(-1).append("\n");
else sb.append(queue.peekLast()).append("\n");
}
}

System.out.println(sb);


br.close();
}
}
25 changes: 25 additions & 0 deletions src/BaekJoon/sa11k/10989/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.io.*;
import java.util.*;

class Main {

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
int[] num = new int[N];

for(int i = 0; i<N; i++){
num[i] = Integer.parseInt(br.readLine());
}

Arrays.sort(num);

for(int i = 0; i<N; i++){
sb.append(num[i]).append("\n");
}

System.out.println(sb);
br.close();
}
}

0 comments on commit 9cb7446

Please sign in to comment.