FJOM On The Run
Mis Bookmarks
Textpattern Forums
Textpattern
Bloglines
Ask Metafilter
Metafilter
Hace mucho que no hacía uno de Top Coder (mientras tanto voy en el capítulo 8 de Head First C#). Pero ahora hice uno mientras Z veía un concurso en la tele.
Aquí va mi respuesta para el TwoRotationCypher
class TwoRotationCypher
{
public String encrypt(int firstSize, int firstRotate, int secondRotate, string message)
{
string resultado = "";
foreach (char caracter in message)
{
if (caracter.Equals(' '))
resultado += caracter;
else
{ // Esto jala como yo lo habría hecho de entrada pero si no rotamos
// solo dentro de los grupos decodificar se hace imposible
// int rotacion = (int)caracter - 97 < firstSize ? firstRotate : secondRotate;
// char c = (char)((((int)caracter - 97 + rotacion) % 26) + 97);
char c;
if ((int)caracter - 97 < firstSize)
{
c = (char)((((int)caracter - 97 + firstRotate) % firstSize) + 97);
}
else
{
c = (char)((((int)caracter - (97 + firstSize)+secondRotate) % (26-firstSize)) + (97 + firstSize));
}
resultado += c;
}
}
return resultado;
}
}
Newer: Top Coder - Huffman Decoding | Home | Older: Head First C#
En línea desde hace 6 años, 3 meses, 17 dÃas, 16 horas y 50 minutos.