Skip to content

Commit 848f3df

Browse files
committed
[Permutation] baekjoon-9742
1 parent be13703 commit 848f3df

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

โ€ŽREADME.md

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@
225225
| 03 | | [Baekjoon-10972 ๋‹ค์Œ ์ˆœ์—ด](./src/Permutation/P10972) | |
226226
| 04 | | [Baekjoon-10973 ์ด์ „ ์ˆœ์—ด](./src/Permutation/P10973) | |
227227
| 05 | | [Baekjoon-10974 ๋ชจ๋“  ์ˆœ์—ด](./src/Permutation/P10974) | |
228+
| 06 | | [Baekjoon-9742 ์ˆœ์—ด](./src/Permutation/P9742) | |
228229

229230
### Probability
230231

โ€Žsrc/Permutation/P9742/Main.java

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package Permutation.P9742;
2+
3+
import java.io.*;
4+
import java.util.*;
5+
6+
public class Main {
7+
8+
static String line, s;
9+
static int pos;
10+
static int[] fact = new int[11];
11+
12+
public static void main(String[] args) throws Exception {
13+
System.setIn(new FileInputStream("src/Permutation/P9742/input.txt"));
14+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
15+
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
16+
17+
fact[1] = 1;
18+
for (int i = 2; i <= 10; i++) fact[i] = fact[i-1] * i;
19+
20+
StringBuilder sb = new StringBuilder();
21+
while ((line = br.readLine()) != null) {
22+
StringTokenizer st = new StringTokenizer(line);
23+
sb.append(line).append(" = ");
24+
25+
s = st.nextToken();
26+
pos = Integer.parseInt(st.nextToken());
27+
28+
if (pos > fact[s.length()]) sb.append("No permutation").append("\n");
29+
else {
30+
pos --;
31+
StringBuffer buf = new StringBuffer(s);
32+
for (int i = s.length()-1; i > 0; i--) {
33+
sb.append(buf.charAt(pos/fact[i]));
34+
buf.deleteCharAt(pos/fact[i]);
35+
pos %= fact[i];
36+
}
37+
sb.append(buf.charAt(0)).append("\n");
38+
}
39+
}
40+
41+
bw.write(sb.toString());
42+
bw.flush();
43+
bw.close();
44+
br.close();
45+
}
46+
}

โ€Žsrc/Permutation/P9742/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## [baekjoon-9742] ์ˆœ์—ด
2+
3+
![image](https://user-images.githubusercontent.com/22045163/106979827-73cb5380-67a2-11eb-94b7-549cafdb4865.png)
4+
![image](https://user-images.githubusercontent.com/22045163/106979878-8ba2d780-67a2-11eb-8231-cb33dfa3a189.png)
5+
6+
![image](https://user-images.githubusercontent.com/22045163/106980001-c86ece80-67a2-11eb-8608-6a3654252a5a.png)

โ€Žsrc/Permutation/P9742/input.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
235 4
2+
bein 20
3+
123456 700
4+
mnpqr 130
5+
tuvwxyz 4000

0 commit comments

Comments
ย (0)