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
Ksju [112]
4 years ago
12

Assume that someone dictates you a sequence of numbers and you need to write it down. For brevity, he dictates it as follows: fi

rst says the number of consecutive identical numbers and then says the number itself. E.g. The sequence 1 1 3 3 3 2 2 2 2 14 14 14 11 11 11 2 will be dictated as "Two one, three three, four twos, three fourteens, three elevens, one two", so you will write down the sequence 2 1 3 3 4 2 3 14 3 11 1 2. The challenge is to write the program which compresses the given sequence using this approach. Input: Your program should read lines from standard input. Each line is a sequence of L integers, where each integer is N, separated by a whitespace. N is in range [0, 99]. L is in range [1, 400]. Output: For each test case, produce a single line of output containing a compressed sequence of numbers separated by a single space char.
Computers and Technology
2 answers:
Basile [38]4 years ago
6 0

Answer:

We have the following code in python with appropriate comments

Explanation:

line = input("Enter your line of integers: ")

# Splits at space

intList = line.split()

#initializing the count to 1

count = 1

#initializing the count to empty string

output = ''

#iterating over the list

for index, x in enumerate(intList):

 

#handling last index separately

if index == len(intList)-1:

if intList[index] == intList[index-1]:

output = output + str(count) + ' ' + str(intList[index])

else:

count = 1

output = output + str(count) + ' ' + str(intList[index])

 

#handling indexes other than the last index    

else:

 

if intList[index]==intList[index+1]:

count = count + 1 #if next integer is same, we increase the count by 1

else:

output = output + str(count) + ' ' + str(intList[index]) + ' '

count = 1

print(output)

Digiron [165]4 years ago
5 0

Answer:

Below is the program

Explanation:

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.nio.charset.StandardCharsets;

import java.util.HashMap;

import java.util.Map;

import java.io.File;

import java.util.Scanner;

import java.util.LinkedHashMap;

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);

   int number = 0;

   int numberOfParagraph = 0;

   int numberOfSequence = 1;

   char ch;

   HashMap<Integer, Integer> map = new HashMap<>();

   String line;

   while ((line = in.readLine()) != null) {

     if(line.equals('\n'))

     {

       numberOfParagraph++;

     }

     if(numberOfParagraph < 1 || numberOfParagraph > 400)

     {

       break;

     }

     for (int index = 0; index < line.length(); index++)

     {

        //number = line.parseInt(line);

        ch = line.charAt(index);

        number = ch - '0';

        if(number < 0 || number > 99)

        {

          continue;

        }

        if(!map.containsKey(number))

        {

          map.put(number, 1);

        }

        else

        {

          numberOfSequence++;

          map.put(number, numberOfSequence);

        }

     }

     //System.out.println(line);

   }

    for (Map.Entry<Integer, Integer> entry : map.entrySet()) {

       System.out.println(entry.getKey() + " ocurrs " + entry.getValue()+ " times");

   }

 }

}

You might be interested in
You use a(n) ____ program to create, send, receive, forward, store, print, and delete e-mail messages.
tigry1 [53]

Answer:

B - E-Mail

Explanation:

This is a program to create, send, receive, forward, store, print, and delete e-mail messages.

3 0
3 years ago
Write an exception class named InvalidTestScore. Modify the TestScores class you wrote in Part I so that it throws an InvalidTes
Elan Coil [88]

Answer:

See Explaination

Explanation:

package testscores;

import java.util.ArrayList;

import java.util.List;

public class TestScores {

public List<Integer> scorearray=new ArrayList<>();

public TestScores(List<Integer> scores) throws InvalidTestScore{

this.scorearray=scores;

for(int i=0;i<scorearray.size();i++){

if(scorearray.get(i)>100 || scorearray.get(i)<0){

throw new InvalidTestScore(this.scorearray.get(i));

}

}

}

public double average(){

int tot=0;

for(int i=0;i<this.scorearray.size();i++){

tot=tot+this.scorearray.get(i);

}

return tot*(1.0)/(this.scorearray.size());

}

class InvalidTestScore extends Exception

{

private double amount;

public InvalidTestScore(int Score)

{

System.out.println("Invalid Score "+Score);

}

}

}

8 0
4 years ago
What occurs when a company knows enough about a customer's likes and dislikes that it can fashion offers more likely to appeal t
Norma-Jean [14]

Answer:

Personalization

Explanation:

Recommendation systems are becoming a powerful tool in our times today, from only shopping to healthcare provision. One major aspect of Recommender systems is Personalization.

Personalization is a concept of adjusting a service or product to greatly suit the customer. Personalization can be drawn by the information provided by the individual such as location, gender, marital status, etc. or drawn from other inferences retrieved from the customer, such as:

  1. the most clicked service category of a customer,
  2. customer browsing patterns or
  3. services or products previously obtained by a customer.

These inferences retrieved from customers can greatly improve customer satisfaction and get them drawn to the system.

5 0
4 years ago
A teacher at your school is using her district issued laptop to create spreadsheets for her part-time job as a bookkeeper. Which
Alenkasestr [34]

Answer:

The teacher is most likely violating the District Use Policy.

5 0
2 years ago
which data representation system is based on the digits 0-9 and is mostly easily interpreted In real wrold situations​
alekssr [168]

Answer:

Hexadecimal  data representation system is based on the digits 0-9 and is mostly easily interpreted In real word situations​ .

Explanation:

Hexadecimal manages sixteen different figures: most often the numbers 0–9 to describe values zero to nine, and (A–F) to describe values ten to fifteen. The modern hexadecimal system was first launched into the domain of computing by IBM in 1963. An older description, with 0-9 and u-z, was practiced in 1956 by the Bendix G-15 computer.

3 0
3 years ago
Other questions:
  • Which payment type is best if you are trying to sick to a budget?
    15·1 answer
  • The __________ is the continuity of control of evidence that makes it possible to account for all that has happened to evidence
    14·2 answers
  • Mobile devices need to work within limited screen space ? true or false
    9·2 answers
  • On most desktop computers, most of the USB ports are on the back of the computer case. Generally, you'll want to connect your mo
    13·1 answer
  • Write a C++ program that takes two numbers from the command line and perform and arithmetic operations with them. Additionally y
    11·1 answer
  • Which option is considered a part of the document that is used to collect specific and predefined information?
    7·1 answer
  • How many votes does a candidate need to become president of the US ?
    12·2 answers
  • Select the correct answer.
    6·1 answer
  • What is density?
    11·1 answer
  • A(n) ____________ is a group of similar or identical computers, connected by a high-speed network, that cooperate to provide ser
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!