Middle three digits: Difference between revisions

m
imported>Arakov
 
(8 intermediate revisions by 2 users not shown)
Line 411:
algoritmo
n=0, c="", m=0,
temp = 0, ctemp=0, candidatos={}
'123, 12345, 1234567, 987654321, 10001, -10001,-123'
Line 423:
temp = string(candidatos * sign(candidatos))
n = len( temp )
mc = replicate (temp, n>=3 && not(is even(n)))
c = replicate (temp, m)
toksep(NL)
print (cat( lpad(" ",11,string(candidatos)), cat(" : ", copy( 3, (n/2-1), c ))),NL)
Line 453 ⟶ 452:
</pre>
<p>VERSION 2:</p>
<syntaxhighlight lang="c">
#include <basico.h>
 
algoritmo
n=0, c="",
temp = 0, candidatos={}
'123, 12345, 1234567, 987654321, 10001, -10001,-123'
'-100, 100, -12345,1, 2, -1, -10, 2002, -2002, 0'
enlistar en 'candidatos'
decimales '0'
tomar 'candidatos' ---retener---, obtenerquitar el signo, multiplicar
convertir a cadena ---retener---, guardarobtener enlargo, mover a 'tempn' ,
guardar en 'temp'
guardar ' replicar ( temp, #(n>=3 && not(is even(n))))' en 'c'
token.separador(NL)
justificar derecha(11,#(string(candidatos))), " : ", concatenar esto
#( copy( 3, (n/2-1), c ) ), unir esto
luego imprime
terminar
</syntaxhighlight>
{{out}}
<pre>
123 : 123
12345 : 234
1234567 : 345
987654321 : 654
10001 : 000
-10001 : 000
-123 : 123
-100 : 100
100 : 100
-12345 : 234
1 :
2 :
-1 :
-10 :
2002 :
-2002 :
0 :
</pre>
 
<p>VERSION 3:</p>
<syntaxhighlight lang="c">
#include <basico.h>
Line 459 ⟶ 507:
n=0, c="", m=0,
temp = 0, candidatos={}
'123, 12345, 1234567, 987654321, 10001, -10001,-123'
'-100, 100, -12345,1, 2, -1, -10, 2002, -2002, 0'
enlistar en 'candidatos'
tomar 'candidatos' ---retener---, obtener signo, multiplicar
convertir a cadena, guardar en 'temp'
decimales '0'
para cada elemento (v,candidatos,17)
tomar'v' ---retener; copiar en 'm'---, obtenerquitar el signo, multiplicar,
guardar en 'v'
#(len( c:=(string(v)) ) ), mover a 'n'
"Num: ",justificar derecha(10,#(string(m))),"(",n,")\t"
si ' #( n>=3 && not(is even(n))) '
"Num: ",justificar derecha(10,#(string(m))),"(",n,")\t puede ser procesado : "
tomar si ( #(n==3), 'c', #( copy( 3, (n/2-1), c )) ), NL
sino
"Num: ",justificar derecha(10,#(string(m))),"(",n,")\tnono puede ser procesado\n"
fin si
luego imprime
Line 2,655 ⟶ 2,702:
if(len<3)
{
InvalidArgumentException.new:("n must have 3 digits or more").raise()
}
else if(len.isEven())
{
InvalidArgumentException.new:("n must have an odd number of digits").raise()
};
Line 2,670 ⟶ 2,717:
{
new int[]{123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0}
.forEach::(n)
{
console.printLine("middleThreeDigits(",n,"):",middleThreeDigits(n) \\ on::(e => e.Message))
}
}</syntaxhighlight>
Line 6,447 ⟶ 6,494:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var middle3 = Fn.new { |n|
Line 6,464 ⟶ 6,511:
 
for (e in a) {
SystemFmt.print("%(Fmt.s(9$9d -> $n", e)), -> %(middle3.call(e))")
}</syntaxhighlight>
 
Anonymous user