QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#13886. If Index

Estadísticas

艾克(Ekko)正在研发他的时光旅行机器,以便在平行宇宙中与爆爆(Powder)重逢。为了实现这一目标,他必须使用一种名为 C-IF 的奇特编程语言编写代码。

C-IF 的语法极其极简:唯一的关键字是 if,且唯一允许的字符是 {},它们必须始终正确匹配。一个 C-IF 程序被认为是合法的,当且仅当:

  • 它仅由 if{} 组成。
  • 它是括号平衡的,这意味着 {} 字符的数量相等,并且我们可以将每个 { 与一个 } 配对,使得 { 字符先出现。

例如,if{{}}ifif{if} 是合法的 C-IF 程序,而 xxx{if}if{ 则不是。

艾克通过“if 指数”(if-index)来衡量一个 C-IF 程序的繁琐程度,其定义如下:

  • 对于每个 if,计算其嵌套深度,定义为包围它的 {} 层数。
  • 给定包含 $n$ 个元素的嵌套深度数组,我们将这些元素按非递减顺序排序后,定义处于第 $\lfloor \frac{n+1}{2} \rfloor$ 个位置的元素为 if 指数(其中第一个元素的索引为 1,最后一个元素的索引为 $n$)。
  • 如果程序中没有 if 语句,我们定义其 if 指数为 $-1$。

请帮助艾克计算一个合法 C-IF 程序的 if 指数。

输入格式

输入仅包含一行,为一个字符串 $S$($|S| \le 5000$),表示一个合法的 C-IF 程序。

输出格式

输出一行,包含一个整数,表示程序 $S$ 的 if 指数。

样例

输入样例 1

if

输出样例 1

0

输入样例 2

if{{ifif}if{if}}

输出样例 2

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.