Write a program to decide who will win if both players do their best.
Input
The input contains the integer from which the game is started.
Output
In the first line you must write 1 if Nikifor wins and 2 otherwise. If Nikifor wins then in the second line you must output the move in the first turn which guarantees victory for him. If there are many such moves then output any of them.
Example
Input:
14
Output:
1
4
https://www.spoj.pl/problems/NGM/
public class AGameWithNumbers { public static void main( String args[] ) throws Exception { int ultimoDigito = System.in.read(); int car = System.in.read(); /* * Es facil de determinar de que el jugador 2 solo ganara * en caso de que el numero inicial termine en 0, en caso * contrario ganara el jugador 1, por tanto es suficiente * con saber cual es el ultimo digito del numero ingresado. */ while( car != 10 && car != -1 ) { ultimoDigito = car; car = System.in.read(); } // Recordar que el 48 es el codigo ASCCI del 0 if( ultimoDigito == 48 ) System.out.println( 2 ); else { System.out.println( 1 ); System.out.println( ultimoDigito - 48 ); } } }
No hay comentarios:
Publicar un comentario