-
Notifications
You must be signed in to change notification settings - Fork 10
/
Typing.java
122 lines (105 loc) · 2.09 KB
/
Typing.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//Calculate Time ###########
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Typing
{
public static int timeCalculate(String[] arrays)
{
int[] timer=new int[arrays.length];
int flag=1,j;
int timer_count=0;
for(int i=0;i<arrays.length;i++)
{
flag=1;
j=i-1;
while(j>=0)
{
if(arrays[i].equals(arrays[j]))
{
timer[i]=timer[j]/2;
timer_count+=timer[i];
flag=0;
break;
}
j--;
}
if(flag!=0)
{
timer[i]=timer(arrays[i]);
timer_count+=timer[i];
}
//System.out.println("timer="+timer[i]);
}
return timer_count;
}
static int timer(String s)
{
int timer=2;
for (int i = 1; i < s.length(); i++)
{
if(s.charAt(i-1)=='d'||s.charAt(i-1)=='f')
{
if(s.charAt(i)=='d'||s.charAt(i)=='f')
{
timer+=4;
}
else if(s.charAt(i)=='k'||s.charAt(i)=='j')
{
timer+=2;
}
}
else if(s.charAt(i-1)=='k'||s.charAt(i-1)=='j')
{
if(s.charAt(i)=='k'||s.charAt(i)=='j')
{
timer+=4;
}
else if(s.charAt(i)=='d'||s.charAt(i)=='f')
{
timer+=2;
}
}
}
return timer;
}
public static void main(String[] args) throws IOException
{
BufferedReader ab = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt (ab.readLine());
if(n<1||n>100)
{
return;
}
int res;
int arraysize;
String[] arrays;
String regex="[kjdf]*";
Pattern pattern = Pattern.compile(regex);
for(int i=0;i<n;i++)
{
arraysize=Integer.parseInt (ab.readLine());
if(arraysize<1||arraysize>100)
{
return;
}
arrays = new String[arraysize];
int c=0;
for(int j=0;j<arraysize;j++)
{
arrays[j] = ab.readLine();
Matcher matcher = pattern.matcher(arrays[j]);
if(!matcher.matches())
{
return;
}
if(arrays[j].length()>20)
{
return;
}
}
res=timeCalculate(arrays);
System.out.println(res);
}
}
}