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.