Skip to content

Instantly share code, notes, and snippets.

@jainal09
Created June 12, 2021 16:03
Show Gist options
  • Save jainal09/0616536283b775491974ceb0ead23b8b to your computer and use it in GitHub Desktop.
Save jainal09/0616536283b775491974ceb0ead23b8b to your computer and use it in GitHub Desktop.
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
class Result {
/*
* Complete the 'findRestaurants' function below.
*
* The function is expected to return a 2D_INTEGER_ARRAY.
* The function accepts following parameters:
* 1. 2D_INTEGER_ARRAY allLocations
* 2. INTEGER numRestaurants
*/
public static List<List<Integer>> findRestaurants(List<List<Integer>> allLocations, int numRestaurants) {
// Write your code here
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int allLocationsRows = Integer.parseInt(bufferedReader.readLine().trim());
int allLocationsColumns = Integer.parseInt(bufferedReader.readLine().trim());
List<List<Integer>> allLocations = new ArrayList<>();
IntStream.range(0, allLocationsRows).forEach(i -> {
try {
allLocations.add(
Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
.map(Integer::parseInt)
.collect(toList())
);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
int numRestaurants = Integer.parseInt(bufferedReader.readLine().trim());
List<List<Integer>> result = Result.findRestaurants(allLocations, numRestaurants);
result.stream()
.map(
r -> r.stream()
.map(Object::toString)
.collect(joining(" "))
)
.map(r -> r + "\n")
.collect(toList())
.forEach(e -> {
try {
bufferedWriter.write(e);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
});
bufferedReader.close();
bufferedWriter.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment