-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy path1235624892.java
47 lines (44 loc) · 1.1 KB
/
1235624892.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
import java.io.*;
import java.math.*;
import java.util.*;
class Codechef {
public static void main(String[] args) throws java.lang.Exception {
PrintWriter pr = new PrintWriter(System.out, true);
Scanner sc=new Scanner(System.in);
int t = sc.nextInt();
String s[];
long time[], tt, sum;
int n, i, j;
char[] temp;
while (t-- != 0) {
n = sc.nextInt();
s = new String[n];
time = new long[n];
for (i = 0; i < n; i++)
s[i] = sc.readLine();
for (i = 0; i < n; i++) {
for (j = 0; j < i; j++) {
if (s[j].equals(s[i])) {
time[i] = time[j] / 2;
break;
}
}
if (j == i) {
temp = s[i].toCharArray();
tt = 2 * temp.length;
for (j = 1; j < temp.length; j++) {
if ((((temp[j] == 'd' || temp[j] == 'f') && (temp[j - 1] == 'd' || temp[j - 1] == 'f')))
|| ((temp[j] == 'j' || temp[j] == 'k') && (temp[j - 1] == 'j' || temp[j - 1] == 'k'))) {
tt = tt + 2;
}
}
time[i] = tt;
}
}
sum = 0;
for (i = 0; i < n; i++)
sum = sum + time[i];
pr.println(sum);
}
}
}