fb:porticula NoPaste
Algo1
Uploader: | max06 |
Datum/Zeit: | 29.01.2012 15:35:17 |
'Compiled with Freebasic 0.23 Linux x86
dim shared counter as unsigned longint = 0
function calc2(M as integer, Compressed as string, proc as integer) as integer
'print str(compressed)
for x as integer = 1 to len(trim(str(M)))
' print "Proc: "+str(proc) : print "Compressed: "+compressed : print "X: "+str(x)
if val(right(compressed, x))=0 then x=x+1
if M >= val(right(compressed, x)) then
if len(compressed)=x and proc=2 then counter += 1: return 1
if len(compressed)=x then return 1
if val(left(right(compressed, x), 1)) = 0 then return 0
counter += calc2(M, left(compressed, len(compressed)-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, Compressed, proc+1)
print "Case #" + str(y) + ": " + str(counter)
counter = 0
next y
end