language: Ruby (ruby-1.9.2)
date: 107 days 13 hours ago
link:
visibility: public
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
t = Integer(gets)
while t > 0
a4 = []
a7 = []
n = Integer(gets)
i = a4.length + 1
if n > a4.length
while i <= n
a4 << i.to_s.count("4")
a7 << i.to_s.count("7")
 
i = i + 1
end
end
l=1
count = 0
while l <= n
i = l
r = l
sum4 = 0
sum7 =0
while r <= n
while i <= r
sum4 = sum4 + a4[i].to_i
sum7 = sum7 + a7[i].to_i
if(sum4 == sum7)
count = count + 1
end
i = i + 1
end
r = r + 1
end
l = l + 1
print "#{count}\n"
end
 
t = t - 1
end