回答編集履歴
2
質問者さんのコードより辞書拝借差し替え
answer
CHANGED
@@ -2,30 +2,27 @@
|
|
2
2
|
「しょうぼうしゃ」の変換は出来ましたので参考までに。
|
3
3
|
2文字のパターンと1文字のパターンを辞書登録さえすればなんでも変換出来るはずです。
|
4
4
|
(未検証)
|
5
|
-
|
6
|
-
全文字パターンとなるとArrayListが大量に必要になるので実用的ではないかも知れません。
|
7
|
-
入力や辞書をどう扱うかは好みで作り変えてください。
|
8
5
|
取り急ぎ全体の流れの参考になればと思います。
|
9
6
|
|
7
|
+
回答編集:
|
8
|
+
辞書のみ質問者さんのコードより拝借し差し替えました。
|
9
|
+
|
10
10
|
###出力結果
|
11
|
-
|
11
|
+
//しょうぼうしゃ
|
12
|
+
//[shoubousha, syoubousya, cilyouboucilya, cixyouboucixya, silyoubousilya, sixyoubousixya, shilyouboushalya, shixyouboushaxya, shoubousha, syoubousya, cilyouboucilya, cixyouboucixya, silyoubousilya, sixyoubousixya, shilyouboushalya, shixyouboushaxya, shoubousha, syoubousya, cilyouboucilya, cixyouboucixya, silyoubousilya, sixyoubousixya, shilyouboushalya, shixyouboushaxya, shoubousha, syoubousya, cilyouboucilya, cixyouboucixya, silyoubousilya, sixyoubousixya, shilyouboushalya, shixyouboushaxya, shoubousha, syoubousya, cilyouboucilya, cixyouboucixya, silyoubousilya, sixyoubousixya, shilyouboushalya, shixyouboushaxya, shoubousha, syoubousya, cilyouboucilya, cixyouboucixya, silyoubousilya, sixyoubousixya, shilyouboushalya, shixyouboushaxya, shoubousha, syoubousya, cilyouboucilya, cixyouboucixya, silyoubousilya, sixyoubousixya, shilyouboushalya, shixyouboushaxya, shoubousha, syoubousya, cilyouboucilya, cixyouboucixya, silyoubousilya, sixyoubousixya, shilyouboushalya, shixyouboushaxya]
|
12
13
|
|
14
|
+
|
13
15
|
```java
|
14
16
|
import java.util.ArrayList;
|
15
17
|
import java.util.HashMap;
|
16
|
-
import java.util.List;
|
17
18
|
import java.util.Map;
|
18
19
|
|
19
20
|
public class memo201 {
|
20
21
|
|
21
|
-
// しょうぼうしゃ
|
22
|
-
// [shoubousha, shoubousya, syoubousha, syoubousya]
|
23
|
-
|
24
22
|
public static void main(String[] args) {
|
25
23
|
|
26
24
|
//辞書作成
|
27
|
-
//
|
25
|
+
//辞書のみ質問者さんのコードより拝借し差し替え
|
28
|
-
//※このサンプルコードでは「しょうぼうしゃ」に必要な辞書しかありません。
|
29
26
|
makeMap();
|
30
27
|
|
31
28
|
//入力
|
@@ -38,36 +35,7 @@
|
|
38
35
|
//出力
|
39
36
|
System.out.println(ans);
|
40
37
|
}
|
41
|
-
|
42
|
-
private static Map<String, List<String>> map = new HashMap<String, List<String>>();
|
43
38
|
|
44
|
-
//しょ
|
45
|
-
private static List<String> setSho = new ArrayList<String>();
|
46
|
-
//う
|
47
|
-
private static List<String> setU = new ArrayList<String>();
|
48
|
-
//ぼ
|
49
|
-
private static List<String> setBo = new ArrayList<String>();
|
50
|
-
//しゃ
|
51
|
-
private static List<String> setSha = new ArrayList<String>();
|
52
|
-
|
53
|
-
private static void makeMap() {
|
54
|
-
|
55
|
-
setSho.add("sho");
|
56
|
-
setSho.add("syo");
|
57
|
-
map.put("しょ", setSho);
|
58
|
-
|
59
|
-
setU.add("u");
|
60
|
-
map.put("う", setU);
|
61
|
-
|
62
|
-
setBo.add("bo");
|
63
|
-
map.put("ぼ", setBo);
|
64
|
-
|
65
|
-
setSha.add("sha");
|
66
|
-
setSha.add("sya");
|
67
|
-
map.put("しゃ", setSha);
|
68
|
-
|
69
|
-
}
|
70
|
-
|
71
39
|
private static ArrayList<String> kanaToRoma(String kana) {
|
72
40
|
ArrayList<String> result = new ArrayList<String>();
|
73
41
|
ArrayList<String> tmp = new ArrayList<String>();
|
@@ -93,7 +61,7 @@
|
|
93
61
|
//組み合わせの数だけ配列を増やす
|
94
62
|
//しゃ=sha,sya=2通り
|
95
63
|
//2通りなら2倍
|
96
|
-
int p = map.get(key).
|
64
|
+
int p = map.get(key).length;
|
97
65
|
|
98
66
|
t *= p;//全通り組み合わせ数
|
99
67
|
|
@@ -108,13 +76,13 @@
|
|
108
76
|
|
109
77
|
int q = result.size();
|
110
78
|
|
111
|
-
|
79
|
+
String[] list = map.get(key);
|
112
80
|
|
113
81
|
int k = 0;
|
114
82
|
for (int j = 0; j < q; j++) {
|
115
83
|
|
116
|
-
tmp.add(result.get(j) + list
|
84
|
+
tmp.add(result.get(j) + list[k]);
|
117
|
-
if (k == list.
|
85
|
+
if (k == list.length - 1) {
|
118
86
|
k = 0;
|
119
87
|
} else {
|
120
88
|
k++;
|
@@ -132,5 +100,16 @@
|
|
132
100
|
}
|
133
101
|
return result;
|
134
102
|
}
|
103
|
+
|
104
|
+
private static Map<String, String[]> map = new HashMap<>();
|
105
|
+
|
106
|
+
private static void makeMap() {
|
107
|
+
map.put("う", new String[] {"u"});
|
108
|
+
map.put("し", new String[] {"si", "shi", "ci"});
|
109
|
+
map.put("ぼ", new String[] {"bo"});
|
110
|
+
map.put("しゃ", new String[] {"sha", "sya", "cilya" , "cixya", "silya", "sixya", "shalya", "shaxya"});
|
111
|
+
map.put("しょ", new String[] {"sho", "syo", "cilyo" , "cixyo", "silyo" , "sixyo", "shilyo" , "shixyo"});
|
112
|
+
}
|
135
113
|
}
|
114
|
+
|
136
115
|
```
|
1
出力結果追加
answer
CHANGED
@@ -4,9 +4,12 @@
|
|
4
4
|
(未検証)
|
5
5
|
|
6
6
|
全文字パターンとなるとArrayListが大量に必要になるので実用的ではないかも知れません。
|
7
|
-
辞書をどう扱うかは好みで作り変えてください。
|
7
|
+
入力や辞書をどう扱うかは好みで作り変えてください。
|
8
8
|
取り急ぎ全体の流れの参考になればと思います。
|
9
9
|
|
10
|
+
###出力結果
|
11
|
+
[shoubousha, syoubousya, shoubousha, syoubousya]
|
12
|
+
|
10
13
|
```java
|
11
14
|
import java.util.ArrayList;
|
12
15
|
import java.util.HashMap;
|