-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from 1821-Study/sa11k
Feat:Add solution of #118
- Loading branch information
Showing
5 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |