Given a pattern as the first argument and a string

Given a pattern as the first argument and a string of blobs split by | show the number of times the pattern is present in each blob and the total number of matches.

Input:

The input consists of the pattern (“bc” in the example) which is separated by a semicolon followed by a list of blobs (“bcdefbcbebc|abcdebcfgsdf|cbdbesfbcy|1bcdef23423bc32” in the example). Example input: bc;bcdefbcbebc|abcdebcfgsdf|cbdbesfbcy|1bcdef23423bc32

Output:

The output should consist of the number of occurrences of the pattern per blob (separated by |). Additionally, the final entry should be the summation of all the occurrences (also separated by |). Example output: 3|2|1|2|8 where bc was repeated 3 times, 2 times, 1 time, 2 times in the 4 blobs passed in. And 8 is the summation of all the occurrences. (3+2+1+2 = 8)

Test 1:

Input: aa;aaaakjlhaa|aaadsaaa|easaaad|sa

Output: 4|4|2|0|10

Code to be used:

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.nio.charset.StandardCharsets;

public class Main {

/**

   * Iterate through 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) {

// Write your code here. Feel free to create more methods and/or classes

}

}

How Our Website Works

1. FILL IN OUR SIMPLE ORDER FORM

It has never been easier to place your order. Fill in the initial requirements in the small order form located on the home page and press “continue” button to proceed to the main order form or press “order” button in the header menu. Starting from there let our system intuitively guide you through all steps of ordering process.

2. PROCEED WITH THE PAYMENT

All your payments are processed securely through PayPal. This enables us to guarantee a 100% security of your funds and process payments swiftly.

3. WRITER ASSIGNMENT

Next, we match up your order details with the most qualified freelance writer in your field.

4. WRITING PROCESS

Once we have found the most suitable writer for your assignment, they start working on a masterpiece just for you!

5. DELIVERY

Once finished, your final paper will be available for download through your personal dashboard. You will also receive an email notification with a copy of your paper attached to it. Sometimes, the writer may leave a note for you about the order in case there is any additional information that they need to give you.

Leave a Reply

Your email address will not be published.