Trouver les crochets correspondants

Étant donné une chaîne composée de crochets ouvrants et fermants, vous devez trouver le crochet ouvrant correspondant à chaque crochet fermant. Il est garanti que la séquence de crochets fournie est valide.

Entrée

L’entrée contient une seule ligne, s (1 ≤ |s| ≤ ).

Sortie

Pour chaque crochet fermant, le programme doit afficher l’indice de son crochet ouvrant correspondant. Les indices doivent être séparés par un espace.

Exemples

Entrée
Sortie
(()())
2 4 1
((()))
3 2 1
()()()
1 3 5

Explication

  1. (()())
    1. Bracket
      (
      (
      )
      (
      )
      )
      Index
      1
      2
      3
      4
      5
      6
      Opening index
      -
      -
      2
      -
      4
      1
  1. ((()))
    1. Bracket
      (
      (
      (
      )
      )
      )
      Index
      1
      2
      3
      4
      5
      6
      Opening index
      -
      -
      -
      3
      2
      1
  1. ()()()
    1. Bracket
      (
      )
      (
      )
      (
      )
      Index
      1
      2
      3
      4
      5
      6
      Opening index
      -
      1
      -
      3
      -
      5
 
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 10 MB

To check your solution you need to sign in
Sign in to continue