CodeDrill
day_streak: --
← 問題一覧に戻る
Python ・ Standard I/O

Problem 61: Checking Matching Parentheses

A string S consisting only of ( and ) is given on one line. If the parentheses match up correctly, output Yes; if not, output No.

For example, (()) and ()() are correct, while ())( and ((( are not.

Constraints

1 ≤ length of S ≤ 1000

Input example 1

(())

Output example 1

Yes

Input example 2

())(

Output example 2

No

What you'll train

Cover the edge cases

What you get

  • Identify boundary conditions
  • Give concrete counterexamples
  • Clarify the judgment criteria

How to ask the AI

Tell the AI that the answer should be No not only when the counts of opening and closing parentheses differ, but also when, like in "())(", the closing parentheses exceed the opening ones partway through even though the total counts match. It also helps to clearly specify how to handle an empty string or a single-character input.

If you ask vaguelyThe AI tends to judge Yes whenever the number of opening and closing parentheses match, often missing cases like "())(" where the balance breaks down partway through.

あなたのコード

実行しました

プレビュー

AIレビュー(プロンプト練習)

コードはChatGPTやClaudeに出させたものを貼って構いません。
ここでの本番は「次にAIへ出す指示」です。評価軸は1つだけ見て、弱点・指示の穴・改善例を返します。
テストに落ちていてもレビューできます。落ちた理由と、指示に足りなかった情報を結びつけます。

先にコードを実行し、テストを1つ以上通してください。