Вопрос задан 18.02.2019 в 14:20. Предмет Информатика. Спрашивает Смирнов Евгений.

Дана строка, содержащая слова. Некоторые из слов взяты в скобки. Написать программу, выводящую

исходную строку без скобок.
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Повираева Олечка.
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));
 }
}
0 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.

0 0

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

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

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