-
Notifications
You must be signed in to change notification settings - Fork 7
/
Main.java
59 lines (48 loc) · 1.05 KB
/
Main.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
package basicLevel1040;
//have three test point failure.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String string = in.nextLine();
in.close();
long[] p = new long[string.length()];
long[] t = new long[string.length()];
for (int i = 0; i < string.length(); i++) {
int j = string.length() - 1 - i;
if (string.charAt(i) == 'P') {
if (i == 0) {
p[i] = 1;
} else {
p[i] = p[i - 1] + 1;
}
} else {
if (i == 0) {
p[i] = 0;
} else {
p[i] = p[i - 1];
}
}
if (string.charAt(j) == 'T') {
if (j == string.length() - 1) {
t[j] = 1;
} else {
t[j] = t[j + 1] + 1;
}
} else {
if (j == string.length() - 1) {
t[j] = 0;
} else {
t[j] = t[j + 1];
}
}
}
double total = 0;
for (int i = 1; i < string.length() - 1; i++) {
if (string.charAt(i) == 'A') {
total = (total + (p[i] * t[i]) % 1000000007) % 1000000007;
}
}
System.out.printf("%.0f", total);
}
}