CF56C.Corporation Mail

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The Beroil corporation structure is hierarchical, that is it can be represented as a tree. Let's examine the presentation of this structure as follows:

  • employee ::= name. | name:_employee_1,_employee_2, ... ,employee__k.
  • name ::= name of an employee

That is, the description of each employee consists of his name, a colon (:), the descriptions of all his subordinates separated by commas, and, finally, a dot. If an employee has no subordinates, then the colon is not present in his description.

For example, line MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY... is the correct way of recording the structure of a corporation where the director MIKE has subordinates MAX, ARTEM and DMITRY. ARTEM has a subordinate whose name is MIKE, just as the name of his boss and two subordinates of DMITRY are called DMITRY, just like himself.

In the Beroil corporation every employee can only correspond with his subordinates, at that the subordinates are not necessarily direct. Let's call an uncomfortable situation the situation when a person whose name is s writes a letter to another person whose name is also s. In the example given above are two such pairs: a pair involving MIKE, and two pairs for DMITRY (a pair for each of his subordinates).

Your task is by the given structure of the corporation to find the number of uncomfortable pairs in it.

Beroil 公司的组织结构是层级制的,即可以表示为一棵树。我们按如下方式描述该结构:

  • 员工 ::= 姓名. | 姓名:_员工_1,_员工_2, … ,员工__k.
  • 姓名 ::= 员工的姓名

也就是说,每位员工的描述由其姓名、一个冒号(:)、所有其下属的描述(以逗号分隔)以及最后的一个句点(.)组成。若某员工没有下属,则其描述中不包含冒号。

例如,字符串 MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY... 是一家公司结构的合法表示,其中负责人 MIKE 有三位下属:MAX、ARTEM 和 DMITRY;ARTEM 有一位下属,名字恰好也是 MIKE(与其上级同名);而 DMITRY 有两位下属,名字均与他自己相同,也叫 DMITRY。

在 Beroil 公司中,每位员工仅可与其下属通信(下属不一定是直接下属,也可为间接下属)。我们将“不适情形”定义为:一名姓名为 s 的员工向另一名姓名同样为 s 的员工发送邮件的情形。在上述示例中,共有两对这样的不适情形:一对涉及 MIKE,另外两对涉及 DMITRY(每名 DMITRY 的下属各构成一对)。

你的任务是:给定公司结构,计算其中不适情形的总对数。

输入格式

The first and single line contains the corporation structure which is a string of length from 1 to 1000 characters. It is guaranteed that the description is correct. Every name is a string consisting of capital Latin letters from 1 to 10 symbols in length.

第一行且唯一一行包含公司结构,该结构是一个长度为 1 至 1000 的字符串。保证该描述是正确的。每个姓名均由 1 至 10 个大写拉丁字母组成。

输出格式

Print a single number — the number of uncomfortable situations in the company.

输出一个整数——公司中不舒适情况的数量。

输入输出样例

  • 输入#1

    MIKE:MAX.,ARTEM:MIKE..,DMITRY:DMITRY.,DMITRY...

    输出#1

    3
  • 输入#2

    A:A..

    输出#2

    1
  • 输入#3

    A:C:C:C:C.....

    输出#3

    6

输入解题思路,AI测评打分。不知道怎么写?

首页