Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package christmaslight;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- public class ChristmasLight {
- public static boolean esPar(int value) {
- if (value%2 == 0) {
- return true;
- }
- return false;
- }
- public static int menor(int a, int b) {
- if (a<b) {
- return a;
- }
- return b;
- }
- public static String calcularEncendidas(int numBombillas, int numInstante) {
- String solucion = "";
- if (numInstante == 0) {
- return "All lights are off :(";
- }
- int i = 0;
- if (esPar(numInstante)) {
- i++;
- }
- int hasta = menor(numInstante-1, numBombillas-2);
- for (;i<hasta;i+=2) {
- solucion += i + " ";
- }
- if (i == hasta) {
- solucion += i;
- }
- if (solucion.isEmpty()) {
- solucion = "All lights are off :(";
- }
- return solucion;
- }
- public static void main(String[] args) {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- try {
- int numCasos = Integer.parseInt(br.readLine());
- for (int i=0; i<numCasos; i++) {
- int numBombillas = Integer.parseInt(br.readLine());
- int numInstante = Integer.parseInt(br.readLine());
- System.out.println(calcularEncendidas(numBombillas, numInstante));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement