Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.00 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Task4b {
  4. public static void main(String[] args) {
  5. Scanner in = new Scanner(System.in);
  6. String[][] arr = {
  7. {"f", "b", "d", "d", "d"},
  8. {"a", "b", "c", "d", "d"},
  9. {"a", "c", "b", "d", "d"},
  10. {"d", "d", "d", "a", "a"},
  11. {"d", "f", "f", "a", "a"}
  12. };
  13. Map<String, Integer> strToInt = new HashMap<String,Integer>();
  14. strToInt.put("a", 0);
  15. strToInt.put("b", 1);
  16. strToInt.put("c", 2);
  17. strToInt.put("d", 3);
  18. strToInt.put("f", 4);
  19. Map<Integer, String> intToStr = new HashMap<Integer, String>();
  20. intToStr.put(0, "a");
  21. intToStr.put(1, "b");
  22. intToStr.put(2, "c");
  23. intToStr.put(3, "d");
  24. intToStr.put(4, "f");
  25.  
  26.  
  27. ArrayList<ArrayList<Integer>> lists1 = new ArrayList<>();
  28.  
  29. for (int i=0; i < 5; i++){
  30. ArrayList<Integer> list = new ArrayList<>();
  31. int temp = i;
  32. list.add(temp);
  33. while (true) {
  34. temp = strToInt.get(arr[temp][i]);
  35. if (list.contains(temp)) {
  36. break;
  37. }
  38. list.add(temp);
  39. }
  40. lists1.add(list);
  41. if (list.size() == 5){
  42. System.out.println(i);
  43. }
  44. }
  45.  
  46. ArrayList<ArrayList<Integer>> lists2 = new ArrayList<>();
  47.  
  48. for (int i=0; i < 5; i++){
  49. for (int j=i+1; j<5; j++){
  50. ArrayList<Integer> list = new ArrayList<>();
  51. for (int k=0; k<lists1.get(i).size(); k++){
  52. if (!list.contains((lists1.get(i).get(k)))) {
  53. list.add(lists1.get(i).get(k));
  54. }
  55. }
  56. for (int k=0; k<lists1.get(j).size(); k++){
  57. if (!list.contains(lists1.get(j).get(k))) {
  58. list.add(lists1.get(j).get(k));
  59. }
  60. }
  61. for (int k=0; k<list.size(); k++){
  62. int temp = list.get(k);
  63. if (temp != i && temp != j) {
  64. for (int a=0; a<lists1.get(temp).size(); a++){
  65. if (!list.contains(lists1.get(temp).get(a))) {
  66. list.add(lists1.get(temp).get(a));
  67. }
  68. }
  69. }
  70. }
  71. for (int l=0; l<list.size(); l++){
  72. for(int m=0; m<list.size(); m++){
  73. int temp = strToInt.get(arr[list.get(l)][list.get(m)]);
  74. if (!list.contains(temp)){
  75. list.add(temp);
  76. if (temp != i && temp != j) {
  77. for (int a=0; a<lists1.get(temp).size(); a++){
  78. if (!list.contains(lists1.get(temp).get(a))) {
  79. list.add(lists1.get(temp).get(a));
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }
  86. lists2.add(list);
  87. if (list.size() == 5){
  88. System.out.println(i + " " + j);
  89. }
  90. }
  91. }
  92.  
  93. ArrayList<ArrayList<Integer>> lists3 = new ArrayList<>();
  94.  
  95. for (int i=0; i < 5; i++) {
  96. for (int j = i + 1; j < 5; j++) {
  97. for (int h=j+1; h<5; h++) {
  98. ArrayList<Integer> list = new ArrayList<>();
  99. for (int k=0; k<lists1.get(i).size(); k++){
  100. if (!list.contains((lists1.get(i).get(k)))) {
  101. list.add(lists1.get(i).get(k));
  102. }
  103. }
  104. for (int k=0; k<lists1.get(j).size(); k++){
  105. if (!list.contains(lists1.get(j).get(k))) {
  106. list.add(lists1.get(j).get(k));
  107. }
  108. }
  109. for (int k=0; k<lists1.get(h).size(); k++){
  110. if (!list.contains(lists1.get(h).get(k))) {
  111. list.add(lists1.get(h).get(k));
  112. }
  113. }
  114. for (int k=0; k<list.size(); k++){
  115. int temp = list.get(k);
  116. if (temp != i && temp != j && temp != h) {
  117. for (int a=0; a<lists1.get(temp).size(); a++){
  118. if (!list.contains(lists1.get(temp).get(a))) {
  119. list.add(lists1.get(temp).get(a));
  120. }
  121. }
  122. }
  123. }
  124. for (int l=0; l<list.size(); l++){
  125. for(int m=0; m<list.size(); m++){
  126. int temp = strToInt.get(arr[list.get(l)][list.get(m)]);
  127. if (!list.contains(temp)){
  128. list.add(temp);
  129. if (temp != i && temp != j) {
  130. for (int a=0; a<lists1.get(temp).size(); a++){
  131. if (!list.contains(lists1.get(temp).get(a))) {
  132. list.add(lists1.get(temp).get(a));
  133. }
  134. }
  135. }
  136. }
  137. }
  138. }
  139. lists3.add(list);
  140. if (list.size() == 5){
  141. System.out.println(i + " " + j + " " + h);
  142. }
  143. }
  144. }
  145. }
  146.  
  147. ArrayList<ArrayList<Integer>> lists4 = new ArrayList<>();
  148.  
  149. for (int i=0; i < 5; i++) {
  150. for (int j = i + 1; j < 5; j++) {
  151. for (int h=j+1; h<5; h++) {
  152. for (int y=h+1; y<5; y++) {
  153. ArrayList<Integer> list = new ArrayList<>();
  154. for (int k = 0; k < lists1.get(i).size(); k++) {
  155. if (!list.contains((lists1.get(i).get(k)))) {
  156. list.add(lists1.get(i).get(k));
  157. }
  158. }
  159. for (int k = 0; k < lists1.get(j).size(); k++) {
  160. if (!list.contains(lists1.get(j).get(k))) {
  161. list.add(lists1.get(j).get(k));
  162. }
  163. }
  164. for (int k = 0; k < lists1.get(h).size(); k++) {
  165. if (!list.contains(lists1.get(h).get(k))) {
  166. list.add(lists1.get(h).get(k));
  167. }
  168. }
  169. for (int k = 0; k < lists1.get(y).size(); k++) {
  170. if (!list.contains(lists1.get(y).get(k))) {
  171. list.add(lists1.get(y).get(k));
  172. }
  173. }
  174. for (int k = 0; k < list.size(); k++) {
  175. int temp = list.get(k);
  176. if (temp != i && temp != j && temp != h && temp != y) {
  177. for (int a = 0; a < lists1.get(temp).size(); a++) {
  178. if (!list.contains(lists1.get(temp).get(a))) {
  179. list.add(lists1.get(temp).get(a));
  180. }
  181. }
  182. }
  183. }
  184. for (int l = 0; l < list.size(); l++) {
  185. for (int m = 0; m < list.size(); m++) {
  186. int temp = strToInt.get(arr[list.get(l)][list.get(m)]);
  187. if (!list.contains(temp)) {
  188. list.add(temp);
  189. if (temp != i && temp != j) {
  190. for (int a = 0; a < lists1.get(temp).size(); a++) {
  191. if (!list.contains(lists1.get(temp).get(a))) {
  192. list.add(lists1.get(temp).get(a));
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. lists4.add(list);
  200. if (list.size() == 5){
  201. System.out.println(i + " " + j + " " + h + " " + y);
  202. }
  203. }
  204. }
  205. }
  206. }
  207.  
  208. int k=0;
  209. }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement