Response:
The code is provided below
Clarification:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
public class Main {
/**
*
* Process each line of input.
*
*/
public static void main(String[] args) throws IOException {
InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
BufferedReader in = new BufferedReader(reader);
String line;
while ((line = in.readLine())!= null) {
String[] splittedInput = line.split(";");
String pattern = splittedInput[0];
String blobs = splittedInput[1];
Main.doSomething(pattern, blobs);
}
}
public static void doSomething(String pattern, String blobs) {
// Implement your code here. You can create more methods or classes if needed
int total = 0;
String arrblobs[] = blobs.split("\\|");
for (int i = 0; i < arrblobs.length; ++i) {
int count = 0, index = 0;
for (;;) {
int position = arrblobs[i].indexOf(pattern, index);
if (position < 0)
break;
count++;
index = position + 1;
}
System.out.print(count + "|");
total += count;
}
System.out.println(total);
}
}