
Вопрос задан 18.02.2019 в 14:20.
Предмет Информатика.
Спрашивает Смирнов Евгений.
Дана строка, содержащая слова. Некоторые из слов взяты в скобки. Написать программу, выводящую
исходную строку без скобок.

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

Отвечает Повираева Олечка.
Class NoBrackets{
public static void main(String args[]){
for(String string = new java.util.Scanner(System.in).nextLine(); string.length()>0; string = string.substring(1,string.length()))
if(string.charAt(0)!=')' && string.charAt(0)!='(')System.out.print(string.charAt(0));
}
}
public static void main(String args[]){
for(String string = new java.util.Scanner(System.in).nextLine(); string.length()>0; string = string.substring(1,string.length()))
if(string.charAt(0)!=')' && string.charAt(0)!='(')System.out.print(string.charAt(0));
}
}



Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.
Problem Analysis
The problem requires writing a program to remove the brackets from a given string. The string contains words, some of which are enclosed in brackets. The program should output the original string without the brackets.Plan
To solve the problem, we can follow these steps: 1. Read the input string. 2. Iterate through each character in the string. 3. If the character is an opening bracket '(', '[' or '{', skip it. 4. If the character is a closing bracket ')', ']' or '}', skip it. 5. Otherwise, append the character to a new string. 6. After iterating through all the characters, output the new string without the brackets.Let's implement this plan in Python.
Solution
Here's the Python code to remove the brackets from a given string:```python def remove_brackets(string): new_string = "" for char in string: if char in ['(', ')', '[', ']', '{', '}']: continue new_string += char return new_string
# Example usage input_string = "This is a (sample) string [with] brackets." output_string = remove_brackets(input_string) print(output_string) ```
Example
Let's consider the example string "This is a (sample) string [with] brackets." The program will remove the brackets and output the following string:``` This is a sample string with brackets. ```
Conclusion
In this response, we discussed a Python program to remove brackets from a given string. The program iterates through each character in the string and skips the brackets, resulting in a new string without the brackets.

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

Информатика 562

Информатика 404

Информатика 31

Информатика 76

Информатика 16

Информатика 41

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