Created
September 15, 2016 13:37
-
-
Save miniharryc/b145fdbcd6ab3491ebbc314a481494fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
import java.util.stream.*; | |
public class Solution { | |
private static final String INSERT = "Insert"; | |
private static final String DELETE = "Delete"; | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
scanner.nextLine(); //discard | |
String values = scanner.nextLine(); | |
List<Integer> list = Arrays.stream( values.split("\\s") ) | |
.mapToInt( Integer::parseInt ) | |
.boxed() | |
.collect( Collectors.toList() ); | |
int numOperations = scanner.nextInt(); | |
IntStream.range(0,numOperations) | |
.forEach( i -> { | |
String op = scanner.next(); | |
if (INSERT.equals(op)) { | |
doInsert(list, scanner); | |
} else { | |
doDelete(list,scanner); | |
} | |
}); | |
String output = list.stream() | |
.map( String::valueOf ) | |
.collect( Collectors.joining(" ") ); | |
System.out.println(output); | |
} | |
private static void doInsert(List<Integer> list, Scanner s) { | |
int x = s.nextInt(); | |
int y = s.nextInt(); | |
list.add(x, y); | |
} | |
private static void doDelete(List<Integer> list, Scanner s) { | |
list.remove(s.nextInt()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment