-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathADACRA.txt
57 lines (44 loc) · 1.25 KB
/
ADACRA.txt
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
test = gets.to_i
test.times do
name=gets.split('').map(&:to_s)
if name.length-1 == name.count('D')
puts 0
elsif name.length-1 == name.count('U')
puts 0
else
names=name.dup
p=0
q=0
x=0
until x == name.length-1
if name[x]=='U'
name[x]='D'
p += 1
y=x+1
while name[y]=='U'
name[y]='D'
y += 1
end
end
x +=1
end
c=0
until c== names.length-1
if names[c]=='D'
names[c]='U'
q += 1
v=c+1
while names[v]=='D'
names[v]='U'
v += 1
end
end
c +=1
end
if p>=q
puts q
else
puts p
end
end
end