Hello,
I might be wrong but from what I understand of your code you change of use
case before reading all the input from the scanner.
Even if the test case retune * you should read all pattern coming before
going to the next.
Le mercredi 22 avril 2020 17:30:08 UTC+2, Berend a écrit :
>
> I'm getting runtime errors and don't know why? Whats my error?
>
> As there are no test tests without asterixes this should work I figured.
>
> import java.io.*;
> import java.util.Scanner;
>
> public class Solution {
>
> public static void main(String[] args) throws FileNotFoundException {
> Scanner in = new Scanner(new BufferedReader(new
> InputStreamReader(System.in)));
> int tests = in.nextInt();
>
> nextTest: for (int test = 0; test < tests; test++) {
> int no_patterns = in.nextInt();
> String beginName = "";
> String endName = "";
> String middleName = "";
> int Case = test + 1;
>
> for (int pat = 0; pat < no_patterns; pat++) {
>
> String pattern = in.next();
>
> String[] pattern_split = pattern.split("\\*", -1);
>
> String next_beginName = pattern_split[0];
> String next_endName = pattern_split[pattern_split.length -
> 1];
>
> for (int i = 1; i < pattern_split.length - 1; i++) {
> middleName += pattern_split[i];
> }
>
> if (beginName.length() == 0) {
> beginName = next_beginName;
> }
> int index_string = beginName.indexOf(next_beginName);
> if (index_string < 0) {
> index_string = next_beginName.indexOf(beginName);
> if (index_string == 0) {
> beginName = next_beginName;
> } else {
> System.out.println("Case #" + Case + ": *");
> continue nextTest;
> }
> } else if (index_string > 0) {
> System.out.println("Case #" + Case + ": *");
> continue nextTest;
> }
>
> if (endName.length() == 0) {
> endName = next_endName;
> }
> String endNameReverse = new
> StringBuilder(endName).reverse().toString();
> String next_endNameReverse = new
> StringBuilder(next_endName).reverse().toString();
> index_string = endNameReverse.indexOf(next_endNameReverse);
> if (index_string < 0) {
> index_string =
> next_endNameReverse.indexOf(endNameReverse);
> if (index_string == 0) {
> endName = next_endName;
> } else {
> System.out.println("Case #" + Case + ": *");
> continue nextTest;
> }
> }
> else if (index_string > 0) {
> System.out.println("Case #" + Case + ": *");
> continue nextTest;
> }
> }
> System.out.println("Case #" + Case + ": " + beginName +
> middleName + endName);
> }
> }
> }
>
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/00e4f9d2-fec9-4a27-9e9e-7c8c76890365%40googlegroups.com.