-
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.
- Loading branch information
Showing
4 changed files
with
181 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,30 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Stack; | ||
|
||
/** | ||
* 제로 | ||
* https://www.acmicpc.net/problem/10773 | ||
*/ | ||
public class Main { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
|
||
public static void main(String[] args) throws IOException { | ||
int k = Integer.parseInt(br.readLine()); | ||
Stack<Integer> stack = new Stack<>(); | ||
|
||
for (int i = 0; i < k; i++) { | ||
int data = Integer.parseInt(br.readLine()); | ||
|
||
if(data == 0) stack.pop(); | ||
else stack.push(data); | ||
} | ||
|
||
System.out.println( | ||
stack.stream() | ||
.mapToInt(Integer::intValue).sum() | ||
); | ||
} | ||
} |
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,68 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.StringTokenizer; | ||
|
||
/** | ||
* 나이순 정렬 | ||
* https://www.acmicpc.net/problem/10814 | ||
*/ | ||
public class Main { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
|
||
public static void main(String[] args) throws IOException { | ||
int n = Integer.parseInt(br.readLine()); | ||
Person[] people = new Person[n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
people[i] = new Person( | ||
Integer.parseInt(st.nextToken()), | ||
st.nextToken() | ||
); | ||
} | ||
|
||
Arrays.stream(people) | ||
.sorted( | ||
Comparator.comparingInt(Person::getAge) | ||
.thenComparing( | ||
Comparator.comparingInt(Person::getId)) | ||
) | ||
.forEach(sb::append); | ||
|
||
System.out.println(sb.toString().trim()); | ||
} | ||
|
||
static class Person{ | ||
static int seq = 0; | ||
int id; | ||
int age; | ||
String name; | ||
|
||
public Person(int age, String name) { | ||
this.id = seq++; | ||
this.age = age; | ||
this.name = name; | ||
} | ||
|
||
public int getAge(){ | ||
return age; | ||
} | ||
|
||
public String getName(){ | ||
return name; | ||
} | ||
|
||
public int getId(){ | ||
return id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return age + " " + name + "\n"; | ||
} | ||
} | ||
} |
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,46 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.StringTokenizer; | ||
|
||
/** | ||
* 숫자 카드 2 | ||
* https://www.acmicpc.net/problem/10816 | ||
*/ | ||
public class Main { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
|
||
public static void main(String[] args) throws IOException { | ||
int n = Integer.parseInt(br.readLine()); | ||
|
||
Map<Integer, Integer> map = new HashMap<>(); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < n; i++) { | ||
int data = Integer.parseInt(st.nextToken()); | ||
if(!map.containsKey(data)){ | ||
map.put(data, 1); | ||
} else { | ||
map.put(data, map.get(data) + 1); | ||
} | ||
} | ||
|
||
int m = Integer.parseInt(br.readLine()); | ||
|
||
st = new StringTokenizer(br.readLine()); | ||
|
||
for (int i = 0; i < m; i++) { | ||
int data = Integer.parseInt(st.nextToken()); | ||
if(!map.containsKey(data)) | ||
sb.append(0) | ||
.append(" "); | ||
else { | ||
sb.append(map.get(data)) | ||
.append(" "); | ||
} | ||
} | ||
System.out.println(sb.toString()); | ||
} | ||
} |
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,37 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Stack; | ||
|
||
/** | ||
* 스택 | ||
* https://www.acmicpc.net/problem/10828 | ||
*/ | ||
public class Main { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
|
||
public static void main(String[] args) throws IOException { | ||
int n = Integer.parseInt(br.readLine()); | ||
Stack<Integer> stack = new Stack<>(); | ||
for (int i = 0; i < n; i++) { | ||
String command = br.readLine(); | ||
if (command.startsWith("push")){ | ||
int data = Integer.parseInt(command.substring(5)); | ||
stack.push(data); | ||
} else { | ||
if (command.equals("top")) { | ||
sb.append(!stack.isEmpty() ? stack.peek() : -1); | ||
} else if (command.equals("pop")){ | ||
sb.append(!stack.isEmpty() ? stack.pop() : -1); | ||
} else if(command.equals("size")){ | ||
sb.append(stack.size()); | ||
} else if(command.equals("empty")){ | ||
sb.append(stack.isEmpty() ? 1: 0); | ||
} | ||
sb.append("\n"); | ||
} | ||
} | ||
System.out.println(sb.toString()); | ||
} | ||
} |