Logo
(追記) (追記ここまで)

4928번 - The Earth is Flat! 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB122292535.211%

문제

Consider the following language:

\( expression = \begin{cases} c & \text {where c is a single, lower-case letter} \\ (e_1 e_2 \cdots e_t n) & \text{zero or more expressions followed by a natural number} \end{cases} \)

The left column of the table below includes sample expressions of this language. Now the flattening of an expression is defined as follows: A single letter is flattened to itself. An expression of the form ( e1 e2 ··· et n ) is flattened by concatenating n copies of the concatenation of the flattening of ei. In other words, if f(e) is the flattening of e, and + symbolizes concatenation, then f( (e1 e2 ··· et n) ) is:

\( \underbrace {f(e_1)+f(e_2) +\cdots+f(e_t)}_{once}+\overbrace {f(e_1)+f(e_2)+\cdots+f(e_t)}^{twice}+\cdots+\underbrace {f(e_1)+f(e_2)+\cdots+f(e_t)}_{n^{th} time} \)

The following tables show some sample expressions and the result of flattening each.

expression flattend expression
w
(c 4)
(a (b c 2) 3) w
cccc
abcbcabcbcabcbc

Write a program to flatten a given expression.

입력

Your program will be tested on one or more test cases. Each test case is made of one correctly formed expression written on a separate line. A ’\$’ character identifies the end of line. The last line of the input, which is not part of the test cases, contains a ’\$’ by itself (possibly with leading and/or trailing white spaces). Every expression in the input is grammatically correct according to the grammar specified above. Note that an expression may contain leading, trailing, and/or embedded spaces. Such spaces should be ignored. Letters and numbers are separated from each other by at least one space character.

출력

For each test case expression, write its flattening on a separate line. There should be no spaces (other than newlines) in the output.

제한

예제 입력 1

w$ 
(c 4)$ 
(a (b c 2) 3)$ 
$

예제 출력 1

w 
cccc 
abcbcabcbcabcbc

힌트

출처

ICPC > Regionals > Africa and Arab > Arab Collegiate Programming Contest > 2005 Arab Collegiate Programming Contest A번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /