Array de leds
Submit solution
Points:
10
Time limit:
5.0s
Memory limit:
256M
Author:
Problem type
Allowed languages
C#, Go, Java, Python
Implementa el mètode switchLed
de la classe LedArray
. El mètode rep com
a paràmetre la posició d'un led i inverteix el seu estat.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class OLed {
boolean state;
void switchOn(){
state = true;
}
void switchOff(){
state = false;
}
void draw(){
if(state){
System.out.print("(*)");
} else {
System.out.print("( )");
}
}
}
class LedArray {
OLed[] leds;
LedArray(int size){
leds = new OLed[size];
for (int i = 0; i < size; i++) {
leds[i] = new OLed();
}
}
void draw(){
for(OLed led : leds){
led.draw();
}
}
}
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
LedArray ledArray = new LedArray(5);
int position;
while((position = scanner.nextInt()) != -1){
ledArray.switchLed(position);
ledArray.draw();
System.out.println();
}
}
}
Input Format
-
Constraints
-
Output Format
-
Sample Input 0
1 2 3 2 -1
Sample Output 0
( )(*)( )( )( )
( )(*)(*)( )( )
( )(*)(*)(*)( )
( )(*)( )(*)( )
Sample Input 1
0 4 2 -1
Sample Output 1
(*)( )( )( )( )
(*)( )( )( )(*)
(*)( )(*)( )(*)
Sample Input 2
0 3 2 4 1 0 4 0 3 2 1 -1
Sample Output 2
(*)( )( )( )( )
(*)( )( )(*)( )
(*)( )(*)(*)( )
(*)( )(*)(*)(*)
(*)(*)(*)(*)(*)
( )(*)(*)(*)(*)
( )(*)(*)(*)( )
(*)(*)(*)(*)( )
(*)(*)(*)( )( )
(*)(*)( )( )( )
(*)( )( )( )( )
Sample Input 3
0 2 4 1 3 0 2 4 1 3 -1
Sample Output 3
(*)( )( )( )( )
(*)( )(*)( )( )
(*)( )(*)( )(*)
(*)(*)(*)( )(*)
(*)(*)(*)(*)(*)
( )(*)(*)(*)(*)
( )(*)( )(*)(*)
( )(*)( )(*)( )
( )( )( )(*)( )
( )( )( )( )( )
Autoria: Gerard Falcó
CC BY-NC-SA 4.0