Вопрос задан 02.05.2019 в 21:32. Предмет Информатика. Спрашивает Жанбырбек Шугыла.

Составьте программу которая позволяет удалить слово t из строки s. Строка s и слово t, которое надо

удалить, вводятся с клавиатуры
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Васюченко Никита.
Пример на c#:
            string s;
            string t;
            Console.WriteLine("Введите строку, из которой нужно удалить определенный текст");
            s = Convert.ToString(Console.ReadLine());
            Console.WriteLine("Введите слово, которое надо удалить");
            t = Convert.ToString(Console.ReadLine());
            Console.WriteLine(s.Replace(t, String.Empty));
            Console.ReadKey();

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Program to Remove a Word from a String

Here is a program in Python that allows you to remove a word from a string. The string and the word to be removed are entered by the user through the keyboard:

```python def remove_word_from_string(s, t): words = s.split() # Split the string into a list of words words = [word for word in words if word != t] # Remove the word 't' from the list result = ' '.join(words) # Join the words back into a string return result

# Get the input from the user s = input("Enter the string: ") t = input("Enter the word to remove: ")

# Call the function to remove the word from the string result = remove_word_from_string(s, t)

# Print the result print("Result:", result) ```

This program takes the input string and word to be removed from the user using the `input()` function. It then splits the string into a list of words using the `split()` method. The program then removes the word 't' from the list using a list comprehension. Finally, it joins the remaining words back into a string using the `join()` method and prints the result.

Please note that this program assumes that the word to be removed is a complete word and not a part of another word. If you want to remove a part of a word, you will need to modify the program accordingly.

I hope this helps! Let me know if you have any further questions.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос