-
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 #173 from 1821-Study/Dltmd202
Feat: Add solution of #118
- Loading branch information
Showing
9 changed files
with
428 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,48 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
|
||
/** | ||
* 큐 | ||
* https://www.acmicpc.net/problem/10845 | ||
*/ | ||
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()); | ||
Queue<Integer> q = new LinkedList<>(); | ||
|
||
for (int i = 0; i < n; i++) { | ||
String command = br.readLine(); | ||
if (command.startsWith("push")){ | ||
q.offer(Integer.parseInt(command.substring(5))); | ||
} else { | ||
if(command.equals("pop")){ | ||
if(!q.isEmpty()) { | ||
sb.append(q.poll()); | ||
} else { | ||
sb.append(-1); | ||
} | ||
} else if(command.equals("size")){ | ||
sb.append(q.size()); | ||
} else if(command.equals("empty")){ | ||
sb.append(q.isEmpty() ? 1: 0); | ||
} else if(command.equals("front")){ | ||
if(!q.isEmpty()){ | ||
sb.append(q.peek()); | ||
} else { | ||
sb.append(-1); | ||
} | ||
} else if(command.equals("back")){ | ||
sb.append(q.stream().reduce((a, b) -> b).orElse(-1)); | ||
} | ||
sb.append("\n"); | ||
} | ||
} | ||
System.out.println(sb.toString().trim()); | ||
} | ||
} |
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,44 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayDeque; | ||
import java.util.Deque; | ||
|
||
/** | ||
* 덱 | ||
* https://www.acmicpc.net/problem/10866 | ||
*/ | ||
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()); | ||
Deque<Integer> deque = new ArrayDeque<>(); | ||
|
||
for (int i = 0; i < n; i++) { | ||
String command = br.readLine(); | ||
if (command.startsWith("push_back")){ | ||
deque.offerLast(Integer.parseInt(command.substring(10))); | ||
} else if(command.startsWith("push_front")){ | ||
deque.offerFirst(Integer.parseInt(command.substring(11))); | ||
} else { | ||
if(command.equals("pop_front")){ | ||
sb.append(deque.isEmpty() ? -1 : deque.pollFirst()); | ||
} else if(command.equals("pop_back")){ | ||
sb.append(deque.isEmpty() ? -1 : deque.pollLast()); | ||
} else if(command.equals("size")){ | ||
sb.append(deque.size()); | ||
} else if(command.equals("empty")){ | ||
sb.append(deque.isEmpty() ? 1: 0); | ||
} else if(command.equals("front")){ | ||
sb.append(deque.isEmpty() ? -1 : deque.peekFirst()); | ||
} else if(command.equals("back")){ | ||
sb.append(deque.isEmpty() ? -1 : deque.peekLast()); | ||
} | ||
sb.append("\n"); | ||
} | ||
} | ||
System.out.println(sb.toString().trim()); | ||
} | ||
} |
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,28 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* 수 정렬하기 3 | ||
* https://www.acmicpc.net/problem/10989 | ||
*/ | ||
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()); | ||
int[] data = new int[n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
data[i] = Integer.parseInt(br.readLine()); | ||
} | ||
Arrays.sort(data); | ||
|
||
for (int i = 0; i < n; i++) { | ||
sb.append(data[i]).append("\n"); | ||
} | ||
System.out.println(sb.toString().trim()); | ||
} | ||
} |
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.StringTokenizer; | ||
|
||
public class Main { | ||
static StringBuilder sb = new StringBuilder(); | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
/** | ||
* 이항 계수 1 | ||
* https://www.acmicpc.net/problem/11050 | ||
*/ | ||
public static void main(String[] args) throws IOException{ | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
int n = Integer.parseInt(st.nextToken()); | ||
int k = Integer.parseInt(st.nextToken()); | ||
int[] factorial = new int[n + 1]; | ||
|
||
factorial[0] = 1; | ||
factorial[1] = 1; | ||
for (int i = 2; i <= n; i++) { | ||
factorial[i] = factorial[i - 1] * i; | ||
} | ||
|
||
System.out.println(factorial[n] / (factorial[n - k] * factorial[k])); | ||
|
||
} | ||
} |
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,58 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.util.stream.*; | ||
|
||
/** | ||
* 좌표 정렬하기1 | ||
* https://www.acmicpc.net/problem/11650 | ||
*/ | ||
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()); | ||
Coordinate[] coordinates = new Coordinate[n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
coordinates[i] = new Coordinate( | ||
Integer.parseInt(st.nextToken()), | ||
Integer.parseInt(st.nextToken()) | ||
); | ||
} | ||
|
||
String answer = Arrays.stream(coordinates) | ||
.sorted(Comparator.comparingInt(Coordinate::getX) | ||
.thenComparing( | ||
Comparator.comparing(Coordinate::getY))) | ||
.map(String::valueOf) | ||
.collect(Collectors.joining("\n")); | ||
|
||
System.out.println(answer); | ||
} | ||
|
||
|
||
static class Coordinate{ | ||
int x; | ||
int y; | ||
|
||
public Coordinate(int x, int y){ | ||
this.y = y; | ||
this.x = x; | ||
} | ||
|
||
public int getY(){ | ||
return y; | ||
} | ||
|
||
public int getX(){ | ||
return x; | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
return x + " " + y; | ||
} | ||
} | ||
} |
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,58 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.util.stream.*; | ||
|
||
/** | ||
* 좌표 정렬하기2 | ||
* https://www.acmicpc.net/problem/11651 | ||
*/ | ||
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()); | ||
Coordinate[] coordinates = new Coordinate[n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
coordinates[i] = new Coordinate( | ||
Integer.parseInt(st.nextToken()), | ||
Integer.parseInt(st.nextToken()) | ||
); | ||
} | ||
|
||
String answer = Arrays.stream(coordinates) | ||
.sorted(Comparator.comparingInt(Coordinate::getY) | ||
.thenComparing( | ||
Comparator.comparing(Coordinate::getX))) | ||
.map(String::valueOf) | ||
.collect(Collectors.joining("\n")); | ||
|
||
System.out.println(answer); | ||
} | ||
|
||
|
||
static class Coordinate{ | ||
int x; | ||
int y; | ||
|
||
public Coordinate(int x, int y){ | ||
this.y = y; | ||
this.x = x; | ||
} | ||
|
||
public int getY(){ | ||
return y; | ||
} | ||
|
||
public int getX(){ | ||
return x; | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
return x + " " + y; | ||
} | ||
} | ||
} |
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,34 @@ | ||
import java.util.*; | ||
import java.io.*; | ||
import java.util.stream.*; | ||
|
||
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{ | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
int n = Integer.parseInt(st.nextToken()); | ||
int k = Integer.parseInt(st.nextToken()); | ||
|
||
List<Integer> q = IntStream.range(1, n + 1) | ||
.boxed() | ||
.collect(Collectors.toList()); | ||
List<Integer> answer = new ArrayList<>(); | ||
|
||
int idx = 0; | ||
while (q.size() > 1){ | ||
idx = (idx + (k - 1)) % q.size(); | ||
|
||
answer.add(q.remove(idx)); | ||
} | ||
answer.add(q.remove(0)); | ||
|
||
System.out.println( | ||
answer.stream() | ||
.map(String::valueOf) | ||
.collect(Collectors.joining(", ", "<", ">")) | ||
); | ||
} | ||
} |
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,27 @@ | ||
import java.io.*; | ||
|
||
/** | ||
* Hashing | ||
* https://www.acmicpc.net/problem/15829 | ||
*/ | ||
public class Main { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
static long MOD = 1234567891; | ||
|
||
public static void main(String[] args) throws IOException{ | ||
int n = Integer.parseInt(br.readLine()); | ||
|
||
char[] plain = br.readLine().toCharArray(); | ||
long res = 0; | ||
long pow = 1; | ||
|
||
for (int i = 0; i < n; i++) { | ||
res += ((plain[i] - 'a' + 1) * pow); | ||
pow = (pow * 31) % MOD; | ||
} | ||
|
||
System.out.println(res % MOD); | ||
|
||
} | ||
} |
Oops, something went wrong.