시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 19 5 5 50.000%

문제

분자 M에 대한 화학식을 통해 어떤 원소로 이루어져 있는지 알 수 있다. 화학식은 다음과 같은 문법을 따른다.

M := G | M G
G := S | S C
S := A | '(' M ')'
C := T | N E
E := D | D E
T := '2' | ... | '9'
N := '1' | ... | '9'
D := '0' | .. | '9'
A := U | U L | U L L 
U := 'A' | .. | 'Z'
L := 'a' | .. | 'z'

카운트 C는 바로 앞에 있는 서브 그룹 S에 곱하는 수이다.

예를 들어, H2O는 두 개의 H(수소)와 한 개의 O(산소) 원소로 이루어져 있다. 또, (Al2C2)3Na4는 3개의 Al(알루미늄), 6개의 C(탄소), 4개의 Na(나트륨)원소로 이루어져 있다.

화학식이 주어졌을 때, 구성하고 있는 원소를 구하는 프로그램을 작성하시오.

입력

입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있고, 올바른 화학식이 주어진다. 각 줄은 100자를 넘지 않는다.

출력

각 테스트 케이스에 대해서, 입력으로 주어진 화학식이 어떤 원소로 이루어져 있는지 예제 출력형식처럼 출력한다. 원소는 사전순으로 출력해야 하고, 원소의 앞에 붙는 수가 1인 경우는 생략해야 한다.

예제 입력 1

H2O
(AlC2)3Na4

예제 출력 1

2H+O
3Al+6C+4Na
W3sicHJvYmxlbV9pZCI6IjQ3OTciLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWQ2NTRcdWQ1NTkiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YmQ4NFx1Yzc5MCBNXHVjNWQwIFx1YjMwMFx1ZDU1YyBcdWQ2NTRcdWQ1NTlcdWMyZGRcdWM3NDQgXHVkMWI1XHVkNTc0IFx1YzViNFx1YjVhNCBcdWM2ZDBcdWMxOGNcdWI4NWMgXHVjNzc0XHViOGU4XHVjNWI0XHVjODM4IFx1Yzc4OFx1YjI5NFx1YzljMCBcdWM1NGMgXHVjMjE4IFx1Yzc4OF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pZCBjaGVtaWNhbCBmb3JtdWxhLiBFYWNoIGxpbmUgd2lsbCBoYXZlIG5vIG1vcmUgdGhhbiAxMDAgY2hhcmFjdGVycy48XC9wPlxyXG4iLCJvdXRwdXQiOiI8cD5Gb3IgZWFjaCBsaW5lIG9mIGlucHV0IHRoZXJlIHdpbGwgYmUgb25lIGxpbmUgb2Ygb3V0cHV0IHdoaWNoIGlzIHRoZSBhdG9taWMgZGVjb21wb3NpdGlvbiBvZiB0aGUgY2hlbWljYWwgaW4gdGhlIGZvcm0gb2YgYSBzdW0gYXMgc2hvd24gaW4gdGhlIHNhbXBsZSBvdXRwdXQuIFRoZSBhdG9tcyBhcmUgbGlzdGVkIGluIGxleGljb2dyYXBoaWNhbCBvcmRlciwgYW5kIGEgY291bnQgb2YgMSBpcyBpbXBsaWVkIGFuZCBub3QgZXhwbGljaXRseSB3cml0dGVuLiBUaGVyZSBhcmUgbm8gYmxhbmsgc3BhY2VzIGluIHRoZSBvdXRwdXQuIEFsbCBvZiB0aGUgY291bnRzIGluIHRoZSBjb3JyZWN0IG91dHB1dCB3aWxsIGJlIHJlcHJlc2VudGFibGUgaW4gMzItYml0IHNpZ25lZCBpbnRlZ2Vycy48XC9wPlxyXG4iLCJoaW50IjoiIiwib3JpZ2luYWwiOiIxIiwiaHRtbF90aXRsZSI6IjAiLCJwcm9ibGVtX2xhbmdfY29kZSI6Ilx1YzYwMVx1YzViNCJ9XQ==

출처

ICPC > Regionals > North America > Rocky Mountain Regional > 2012 Rocky Mountain Regional Contest B번

  • 문제를 번역한 사람: baekjoon
  • 어색한 표현을 찾은 사람: bupjae