FJOM On The Run
Mis Bookmarks
Textpattern Forums
Textpattern
Bloglines
Ask Metafilter
Metafilter
Otro que en ruby habría sido más sencillo.
Enunciado
class Rochambo
{
static public int wins(string opponent)
{
int win = 0;
char ultima = '0';
char penultima = '0';
char[] opciones={'R','P','S'};
foreach (char turnoOp in opponent)
{
char prediccion=new char();
if (penultima.Equals('0'))
prediccion='S';
else if (penultima.Equals(ultima))
prediccion = ultima;
else
{
foreach (char op in opciones)
{
if (!op.Equals(ultima) && !op.Equals(penultima))
prediccion = op;
}
}
if (ganador(turnoYo(prediccion),turnoOp))
win++;
penultima = ultima;
ultima = turnoOp;
}
return win;
}
static char turnoYo(char prediccion)
{
if (prediccion.Equals('S')) return 'R';
if (prediccion.Equals('R')) return 'P';
if (prediccion.Equals('P')) return 'S';
return 'E';
}
static bool ganador(char yo, char op)
{
if (yo.Equals('R') && op.Equals('S'))
return true;
if (yo.Equals('S') && op.Equals('P'))
return true;
if (yo.Equals('P') && op.Equals('R'))
return true;
return false;
}
}
Newer: TopCoder SRM 431 | Home | Older: Top Coder - Movie Rating
En línea desde hace 5 años, 10 meses, 27 dÃas, 20 horas y 24 minutos.