Created
June 5, 2019 18:33
-
-
Save nosrednawall/2891c8c8b369b5c2b3b327fd0304e27a to your computer and use it in GitHub Desktop.
resolução da questão Compare the Triplets
This file contains hidden or 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.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; | |
public class Solution { | |
// Complete the compareTriplets function below. | |
static List<Integer> compareTriplets(List<Integer> a, List<Integer> b) { | |
List<Integer> resultado = new ArrayList<Integer>(); | |
int max = a.size(); | |
int alice = 0; | |
int bob = 0; | |
for(int i = 0; i < max ; i++){ | |
if(a.get(i) > b.get(i)){ | |
alice ++; | |
}else if(a.get(i) < b.get(i)){ | |
bob++; | |
} | |
} | |
resultado.add(0,alice); | |
resultado.add(1,bob); | |
return resultado; | |
} | |
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"))); | |
List<Integer> a = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) | |
.map(Integer::parseInt) | |
.collect(toList()); | |
List<Integer> b = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" ")) | |
.map(Integer::parseInt) | |
.collect(toList()); | |
List<Integer> result = compareTriplets(a, b); | |
bufferedWriter.write( | |
result.stream() | |
.map(Object::toString) | |
.collect(joining(" ")) | |
+ "\n" | |
); | |
bufferedReader.close(); | |
bufferedWriter.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment