
При вёрстке у редактора газеты Кости осталась одна строка на n символов. Надо её заполнить, поэтому
он решил поместить туда секретный шифр. Шифр у него уже есть, и, если получится, Костя собирается повторить его несколько раз, чтобы заполнить всё место. Обрезать шифр нельзя — тогда потеряется его смысл.Дана непустая строка с шифром и число символов для заполнения n. Выведи получившуюся у Кости строку или строку "не получится".Ввод: Шифр 12; Шифр 5Вывод: ШифрШифрШифр; не получится

Ответы на вопрос

Программа:
Python:
cipher, n = map(str, input().split())
if int(n) % len(cipher) == 0:
print(cipher * int(int(n)/len(cipher)))
else:
print('не получится')
В начале вводим значения переменным согласно условию. Из задачи можно понять, что на выходе должно быть только n чисел, а само слово не должно быть оборвано. Если это условие не выполняется - выводится "не получится". Поэтому делается проверка, остаток от деления n на кол-во символов в шифре равен ли нулю. Если так, то выводим шифр n/len(шифр) раз. Если нет, то просто выводим строку "не получится".



Problem Analysis
Kostya, a newspaper editor, has one line left to fill with a secret cipher. He already has the cipher and wants to repeat it multiple times to fill the remaining space. However, he cannot trim the cipher because it would lose its meaning. We need to take a non-empty string representing the cipher and the number of characters to fill, and output the resulting line or "не получится" (which means "it won't work" in Russian) if it is not possible to fill the remaining space.Plan
To solve this problem, we can follow these steps: 1. Read the input string representing the cipher and the number of characters to fill. 2. Calculate the length of the cipher. 3. If the length of the cipher is greater than the number of characters to fill, output "не получится". 4. Otherwise, calculate the number of times the cipher needs to be repeated to fill the remaining space. 5. Repeat the cipher the required number of times and output the resulting line.Let's implement this plan in code.
Solution
Here's a possible implementation in Python:```python cipher, n = input().split(';') n = int(n) cipher_length = len(cipher)
if cipher_length > n: print("не получится") else: repetitions = n // cipher_length remaining_characters = n % cipher_length result = cipher * repetitions + cipher[:remaining_characters] print(result) ```
Example
Input: ``` Шифр 12; Шифр 5 ```Output: ``` ШифрШифрШифр; не получится ```
Explanation
In this example, the input cipher is "Шифр" and the number of characters to fill is 12. The length of the cipher is 4. Since the length of the cipher is less than the number of characters to fill, we can repeat the cipher 3 times to fill the remaining space. The resulting line is "ШифрШифрШифр".

Похожие вопросы
Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili