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
Alborosie
4 years ago
5

We consider a string with only alphabets 'a', 'b', 'c'. A string is diverse if no three consecutive letters are the same. Meanin

g that a diverse string cannot contain strings 'aaa', 'bbb', 'ccc'.
Write the most efficient Python program that given three integers A,B and C, it returns any longest diverse string containing at most A 'a's, B 'b's, and C 'c's. If generating a string is impossible return a blank string.

Eg.

Given A=6, B=1, C=1

The program may return aabaacaa. Note that aacaabaa is also valid.

Given A=0, B=1, C=8

The only correct string is ccbcc
Computers and Technology
1 answer:
hram777 [196]4 years ago
8 0

Answer:

from itertools import permutations

import math

import re

a = int(input())

b = int(input())

c = int(input())

num = math.ceil((a + b + c) / 2)

str_val = a*'a'+b*'b'+c*'c'

str_per = list(set(list(permutations(str_val))))

temp_str, output_str = [], []

val = ["".join(i) for i in str_per]

for each in val:

   all_find_str = re.findall(r"([a-z])\1{2,}", each)

   if not all_find_str:

       output_str.append(each)

   else:

       all_find_str = re.findall(r"([a-z])\1{2,}", each[:num])

       if not all_find_str:

           temp_str.append(each[:num])

if output_str:

   print((output_str[0]))

else:

   print("Output is:", set(temp_str))

Explanation:

We first need to have all necessary modules imported.

This is a permutation related question and we will be using the permutation module. The math and regular expression module is also imported.

The program begins by getting the user inputs for <em>a, b, c</em>.

A permutation is ran based on the values of the letters. Permutations work by finding the number of ways the strings can be joined.

If the permutation is more than one, the first index is the default output. If a single string is generated, it will be the output. A blank string will be the output if generating a string is impossible.

You might be interested in
Henry is working from a USDA office. He has several tasks to perform today: 1) he logs onto his USDA computer to get started; 2)
Ksivusya [100]

Answer:

  A. Using a cell phone to discuss sensitive information

Explanation:

In general, cell phone signals are not secure. Cell phones without appropriate encryption should never be used to discuss sensitive information.

3 0
3 years ago
Technology and Communications Quiz Active 1 Which of the following inventions has had the greatest impact on sound technology? A
liraira [26]

Answer:

B the tape recorder bec half century later made sonorities not only reproducible but also alterable.

6 0
3 years ago
Which pdu is processed when a host computer is de-encapsulating a message at the transport layer of the tcp/ip model?.
yulyashka [42]

The PDU that is processed when a host computer is de-encapsulating a message at the transport layer of the tcp/ip model is segment.

<h3>What is this PDU about?</h3>

Note that in the transport layer, a host computer is said to often de-encapsulate  what we call a segment so that they can be able to put back data to an acceptable or given format through the use of the application layer protocol that belongs to the TCP/IP model.

Therefore, The PDU that is processed when a host computer is de-encapsulating a message at the transport layer of the tcp/ip model is segment as it is the right thing to do.

Learn more about host computer from

brainly.com/question/553980

5 0
2 years ago
Which was first launched during the space race
Leni [432]

Answer:

Sputnik

Explanation:

On October 4, 1957, a Soviet R-7 intercontinental ballistic missile launched Sputnik (Russian for “traveler”), the world's first artificial satellite, and the first man-made object to be placed into the Earth's orbit.

3 0
4 years ago
This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by
kompoz [17]

Answer:

The modified program in Java is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

 int arrowHeadWidth, arrowBaseWidth, arrowBaseHeight;

 System.out.print("Head Width: "); arrowHeadWidth = input.nextInt();

 System.out.print("Base Width: "); arrowBaseWidth = input.nextInt();

 System.out.print("Base Height: "); arrowBaseHeight = input.nextInt();

 while (arrowHeadWidth <= arrowBaseWidth) {

       System.out.print("Head Width: "); arrowHeadWidth = input.nextInt();

 System.out.print("Base Width: "); arrowBaseWidth = input.nextInt();      }

 for(int i = 0; i<arrowBaseHeight; i++){

     for(int j = 0; j<arrowBaseWidth;j++){

         System.out.print("*");        }

         System.out.println();    }

 for(int i = arrowHeadWidth; i>0;i--){

     for(int j = 0; j<i;j++){

         System.out.print("*");        }

         System.out.println();    }

}

}

Explanation:

This declares the arrow dimensions

 int arrowHeadWidth, arrowBaseWidth, arrowBaseHeight;

This get input for the head width

 System.out.print("Head Width: "); arrowHeadWidth = input.nextInt();

This get input for the base width

 System.out.print("Base Width: "); arrowBaseWidth = input.nextInt();

This get input for the base height

 System.out.print("Base Height: "); arrowBaseHeight = input.nextInt();

This loop is repeated until the head width is greater than the base width

<em>  while (arrowHeadWidth <= arrowBaseWidth) {</em>

<em>        System.out.print("Head Width: "); arrowHeadWidth = input.nextInt();</em>

<em>  System.out.print("Base Width: "); arrowBaseWidth = input.nextInt();      }</em>

This iterates through the base height

 for(int i = 0; i<arrowBaseHeight; i++){

This iterates through the base width

     for(int j = 0; j<arrowBaseWidth;j++){

This fills the base

         System.out.print("*");        }

This prints a new line

         System.out.println();    }

These iterate through the arrow head

<em>  for(int i = arrowHeadWidth; i>0;i--){</em>

<em>      for(int j = 0; j<i;j++){</em>

This fills the arrow head

         System.out.print("*");        }

This prints a new line

         System.out.println();    }

5 0
3 years ago
Other questions:
  • Protected base class members cannot be accessed by: a.friends of the base class.
    6·1 answer
  • On the Internet, you can use a(n)______to look for information on any topic, such as books, movies, scholarly articles, news, an
    6·2 answers
  • Computer security:
    15·1 answer
  • Se Statements
    6·1 answer
  • Write the name of the tab, command group, and icon that is used to create multilevel lists.
    12·1 answer
  • In popular usage and in the media, the term ________ often describes someone who breaks into a computer system without authoriza
    10·1 answer
  • Which of the following is time-dependant? Group of answer choices
    8·1 answer
  • This assignment is based on Exercise 8.4 from your textbook. Each of the following Python functions is supposed to check whether
    11·1 answer
  • Differentiate between soft copy output and hard copy output?​
    12·2 answers
  • TensorFlow and Pytorch are examples of which type of machine learning platform?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!