1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
SpyIntel [72]
3 years ago
14

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 b

lob 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|1bcdef23423bc32Output: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|saOutput: 4|4|2|0|10Code 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}}
Computers and Technology
1 answer:
Ierofanga [76]3 years ago
5 0

Answer:

The code is below

Explanation:

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

      int sum = 0;

      String arrblobs[] = blobs.split("\\|");

      for (int i = 0; i < arrblobs.length; ++i) {

          int answer = 0, index = 0;

          for (;;) {

              int position = arrblobs[i].indexOf(pattern, index);

              if (position < 0)

                  break;

              answer++;

              index = position + 1;

          }

          System.out.print(answer + "|");

         

          sum = sum + answer;

      }

      System.out.println(sum);

  }

}

You might be interested in
Which relation is created with the primary key associated with the relationship or associative entity, plus any non-key attribut
konstantin123 [22]

Answer:

- Transform binary or unary M:N relationship or associative entity with its own key.

Explanation:

Transform binary relation is described as the method through which a decimal can easily be converted into binary while the unary relationship is described as a relationship in which both the two participants occurs from the same entity.

In the given case, 'transform binary or unary M:N relationship' can be created using 'the primary key linked with the relationship plus any non-key aspects of the relationship and the primary keys of the related entities' as it displays the existence of a relationship between the occurrences of a similar set of the entity i.e. associative entity here.

5 0
4 years ago
A certain audio compact disc (cd) contains 783.216 megabytes of digital information. each byte consists of exactly 8 bits. when
kakasveta [241]
You are not putting the question but I can guess that it asking for the CD duration. To answer this question, you need to convert the CD capacity unit(783.216 megabyte) into megabits which were used for the cd read rate (1.4 megabits/s). The calculation would be:

CD duration: CD capacity / rate= 783.216 megabytes *(8 megabits/megabyte) / (1.4 megabits /s)= 4475.52 second or 74.6 minutes
3 0
4 years ago
Write an if/else statement that adds 1 to the variable minors if the variable age is less than 18, adds 1 to the variable adults
Mama L [17]

Answer:

Explanation:

data is a statement like

data 10,20, 30 , 40 , 50, 60 , 70, 80

\\the numbers represent ages.

For x := 1 to end of data do a[x]:=read(data)

\\ This is a comment. You could do this much easier if you just use three if statements rather than the if then else.

minor:=0;adult:=0;senior:=0;

while a[x] <> 0 do begin

age:= a[x]

if age < 19 then minor:=minor + 1;

If age > 18 then if age < 65 the adult:=adult + 1;

if age > 64 then senior := senior + 1;

end;

I have not declared the variables anywhere. That depends on what language you are using. The key step you  want are the three if statements. How you find out what's in them is another matter.

6 0
3 years ago
In relation to data science,advances in technology has made it more feasible to do what
Reika [66]
In recent years data science has become less and less about the data itself, and more about the technology and tools used to interact with it. Advanced solutions like AI, machine learning and robust analytics tools make it possible not just to process and understand massive stores of information but at unprecedented speeds.
3 0
3 years ago
Imagine that you have just been given a super high-tech, life-sized robot that can communicate with you and accomplish tasks. De
Svetlanka [38]

Answer:

The robot has several inputs for speech recognition and sight like a microphone (as its ears) and cameras for sight. The robot has neural networks of programmed instructions in its processor which is used to process data received from the input devices and the result comes out as a response (like the robot speaking with a speaker as its mouth). This clearly defines the robot as a computer system.

Explanation:

A computer system is an electronic device that accepts input from a user or its surrounding, processes the data received and returns the output of the processed data.

The robot is able to receive data, process the data with its processor and responds or sends feedback to the user.

4 0
3 years ago
Other questions:
  • Submit your 300-word essay describing the equipment usedI in a well-equipped studio’s audio department and the training and expe
    8·2 answers
  • Describe how an attacker can use whois databases and the nslookup tool to perform reconnaissance on an institution before launch
    8·1 answer
  • A city-wide wireless network is an example of which type of network?<br> CAN<br> MAN<br> WAN<br> WMN
    7·1 answer
  • PLZ HELP!! How does HTML help solve the problem of telling a computer what a web page looks like, not just the content that is o
    15·1 answer
  • Bradley is working on a program that uses different classes in specific relationships. Help him remember what these relationship
    14·1 answer
  • Which computer can perform the single dedicated task? a. Which commuter can perform the function of both analog and digital devi
    6·1 answer
  • What sort of technique would you use to sort 10,000 items using just 1000 available slot in your RAM?
    6·1 answer
  • B. Directions: Fill in the blanks with the correct answer.
    13·1 answer
  • What would be the printed output of the Python code to the right?
    14·1 answer
  • Explain briely what this statement mean.<br>"A byte is equivalent to a character"<br>​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!