-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem13.java
101 lines (76 loc) · 2.13 KB
/
Problem13.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package dimikOJ;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Problem13 {
public static int getFactorial(int number) {
int factorial = 1;
if (number == 0 || number == 1) {
return factorial;
} else {
for (int i = number; i >= 1; i--) {
factorial = factorial * i;
}
return factorial;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
String line;
int lineLength;
String[] lineInArray;
String[] lines;
int N = input.nextInt();
while (N < 1) {
N = input.nextInt();
}
lines = new String[N];
for (int i = 0; i < N; i++) {
line = input.nextLine();
lineLength = line.trim().split("\\s+").length;
lineInArray = line.trim().split("\\s+");
boolean allFine = true;
for (String word : lineInArray) {
if (word.length() < 1 || word.length() > 20) {
allFine = false;
break;
}
}
while (lineLength < 1 || lineLength > 10 || allFine == false) {
line = input.nextLine();
lineLength = line.trim().split("\\s+").length;
lineInArray = line.trim().split("\\s+");
allFine = true;
for (String word : lineInArray) {
if (word.length() < 1 || word.length() > 20) {
allFine = false;
break;
}
}
}
lines[i] = line;
}
input.close();
for (int i = 0; i < lines.length; i++) {
ArrayList<String> wordsList = new ArrayList<String>();
lineInArray = lines[i].trim().split("\\s+");
for (String word : lineInArray) {
wordsList.add(word);
}
int denominator = 1;
for (int j = 0; j < wordsList.size();) {
int counter = 0;
for (int j2 = 0; j2 < lineInArray.length; j2++) {
if (wordsList.get(j).equals(lineInArray[j2])) {
counter++;
}
}
denominator = denominator * getFactorial(counter);
wordsList.removeAll(Collections.singleton(wordsList.get(j)));
}
int n = getFactorial(lines[i].trim().split("\\s+").length) / denominator;
System.out.printf("1/%d\n", n);
}
}
}