FJOM On The Run
Mis Bookmarks
Textpattern Forums
Textpattern
Bloglines
Ask Metafilter
Metafilter
Retomando C# y Ruby porque me he atorado un poco en retomar Scheme:
Aqui esta el enunciado del problema
class StringMult
//SRM 199 DIV 2. 250 Point
{
public string times(string sFactor, int iFactor)
{
string repetir="";
if (iFactor==0 || sFactor==""){return "";}
if (iFactor > 0) {repetir=sFactor; }
else
{
iFactor *= -1;
for (int i = sFactor.Length-1; i >=0; i--)
{
repetir += sFactor[i];
}
}
string temp="";
for (int i = 0; i < iFactor; i++)
{
temp+=repetir;
}
return temp;
}
}
En ruby es trivial, la mayor “dificultad” es ponerlo en el formato de topcoder. Sería mas práctico hacer el override al metodo * de la clase String original para agregar los multiplicadores negativos.
class StringMult
def times(sFactor, iFactor)
return sFactor.reverse*(iFactor*-1) if (iFactor<0)
return sFactor*iFactor
end
end
Newer: Project Euler 12 | Home | Older: Programacion HDTP Capitulo 6 - 1
En línea desde hace 4 años, 8 meses, 23 dÃas, 11 horas y 1 minuto.