CF190C.STL

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer.

We all know that programs often store sets of integers. For example, if we have a problem about a weighted directed graph, its edge can be represented by three integers: the number of the starting vertex, the number of the final vertex and the edge's weight. So, as Vasya was trying to represent characteristics of a recently invented robot in his program, he faced the following problem.

Vasya is not a programmer, so he asked his friend Gena, what the convenient way to store n integers is. Gena used to code in language X-- and so he can use only the types that occur in this language. Let's define, what a "type" is in language X--:

  • First, a type is a string "int".
  • Second, a type is a string that starts with "pair", then followed by angle brackets listing exactly two comma-separated other types of language X--. This record contains no spaces.
  • No other strings can be regarded as types.

More formally: type := int | pair<type,type>. For example, Gena uses the following type for graph edges: pair<int,pair<int,int>>.

Gena was pleased to help Vasya, he dictated to Vasya a type of language X--, that stores n integers. Unfortunately, Gena was in a hurry, so he omitted the punctuation. Now Gena has already left and Vasya can't find the correct punctuation, resulting in a type of language X--, however hard he tries.

Help Vasya and add the punctuation marks so as to receive the valid type of language X--. Otherwise say that the task is impossible to perform.

战争爆发前,瓦夏曾是一名会计,也是为数不多懂得操作计算机的人之一,因此被任命为程序员。

众所周知,程序中常常需要存储整数集合。例如,在处理带权有向图的问题时,一条边可以用三个整数来表示:起点顶点编号、终点顶点编号以及该边的权重。因此,当瓦夏试图在程序中表示一种新近发明的机器人的特性时,他遇到了如下问题。

瓦夏并非专业程序员,于是他向朋友吉娜请教:存储 nn 个整数的“方便方式”是什么?吉娜过去使用语言 X-- 编程,因此他只能使用该语言中所支持的数据类型。下面我们来定义语言 X-- 中的“类型”:

  • 首先,“类型”可以是字符串 "int";
  • 其次,“类型”也可以是一个以 "pair" 开头、后接尖括号 < > 的字符串,其中尖括号内恰好包含两个由逗号分隔的、属于语言 X-- 的其他类型;该字符串中不包含任何空格;
  • 除此之外,其他任何字符串均不能被视为合法类型。

更形式化地定义为:type := int | pair<type,type>。例如,吉娜用如下类型表示图的边:pair<int,pair<int,int>>。

吉娜很乐意帮助瓦夏,便口述了一个能存储 nn 个整数的语言 X-- 类型给瓦夏。不幸的是,吉娜当时很匆忙,遗漏了所有标点符号。如今吉娜已经离开,而瓦夏无论如何努力,都无法还原出正确的标点,从而得到一个合法的语言 X-- 类型。

请帮助瓦夏,在给定字符串中添加必要的标点符号(即逗号 , 和尖括号 <, >),使其成为一个合法的语言 X-- 类型;若不可能实现,则说明该任务无法完成。

输入格式

The first line contains a single integer n (1 ≤ n ≤ 105), showing how many numbers the type dictated by Gena contains.

The second line contains space-separated words, said by Gena. Each of them is either "pair" or "int" (without the quotes).

It is guaranteed that the total number of words does not exceed 105 and that among all the words that Gena said, there are exactly n words "int".

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5),表示 Gena 所描述的类型中包含的数字个数。

第二行包含若干由空格分隔的单词,这些单词均为 Gena 所说的内容。每个单词要么是 "pair",要么是 "int"(不带引号)。

保证所有单词的总数不超过 10510^5,且在 Gena 所说的所有单词中,恰好有 nn 个单词为 "int"。

输出格式

If it is possible to add the punctuation marks so as to get a correct type of language X-- as a result, print a single line that represents the resulting type. Otherwise, print "Error occurred" (without the quotes). Inside the record of a type should not be any extra spaces and other characters.

It is guaranteed that if such type exists, then it is unique.

Note that you should print the type dictated by Gena (if such type exists) and not any type that can contain n values.

如果可以通过添加标点符号,使得最终得到的语言类型为正确的类型 XX,则输出一行,表示该结果类型。否则,输出 "Error occurred"(不带引号)。类型记录中不应包含任何额外的空格及其他字符。

保证:若满足条件的类型存在,则该类型是唯一的。

注意:你应该输出由 Gena 指定的类型(如果该类型存在),而不是任意一个能容纳 nn 个值的类型。

输入输出样例

  • 输入#1

    3
    pair pair int int int

    输出#1

    pair&lt;pair&lt;int,int&gt;,int&gt;
  • 输入#2

    1
    pair int

    输出#2

    Error occurred

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

首页