fb:porticula NoPaste
Algo2
Uploader: | max06 |
Datum/Zeit: | 29.01.2012 17:00:50 |
'Compiled with Freebasic 0.23 Linux x86
dim shared counter as unsigned longint = 0
dim shared test as integer
function calc2(M as integer, M_len as integer, Compressed as string, position as integer, proc as integer) as integer
'print str(compressed)
for x as integer = 1 to M_len
' print "Proc: "+str(proc) : print "Compressed: "+compressed : print "X: "+str(x)
'if val(right(compressed, x))=0 then x=x+1
if chr(compressed[position]) = "0" then x=x+1
if x=1 then test = val(chr(compressed[position]))
if x=2 then test = 10*val(chr(compressed[position-1]))+val(chr(compressed[position]))
if x=3 then test = 100*val(chr(compressed[position-2]))+10*val(chr(compressed[position-1]))+val(chr(compressed[position]))
'print "X: "+str(x)+" - Test: "+str(test)
'sleep 500
'if M >= val(right(compressed, x)) then
if M >= test then
if position+1=x and proc=2 then counter += 1: return 1
if position+1=x then return 1
if chr(compressed[position-x+1]) = "0" then return 0
counter += calc2(M, M_len, compressed, position-x, proc+1)
end if
next x
return 0
end function
dim as string fromfile
dim as integer M
dim as string compressed
dim as integer proc=1
open command(1) for input as #1
line input #1, fromfile
dim as integer x = val(fromfile)
for y as integer = 1 to x
line input #1, fromfile
M = val(trim(left(fromfile, instr(fromfile, " "))))
Compressed = trim(mid(fromfile, len(M)))
calc2(M, len(trim(str(M))), Compressed, len(compressed)-1, proc+1)
print "Case #" + str(y) + ": " + str(counter)
counter = 0
next y