시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 128 MB 5 2 2 40.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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gZm9ybXVsYS4gRWFjaCBsaW5lIHdpbGwgaGF2ZSBubyBtb3JlIHRoYW4gMTAwIGNoYXJhY3RlcnMuPFwvcD5cclxuIiwib3V0cHV0IjoiPHA+Rm9yIGVhY2ggbGluZSBvZiBpbnB1dCB0aGVyZSB3aWxsIGJlIG9uZSBsaW5lIG9mIG91dHB1dCB3aGljaCBpcyB0aGUgYXRvbWljIGRlY29tcG9zaXRpb24gb2YgdGhlIGNoZW1pY2FsIGluIHRoZSBmb3JtIG9mIGEgc3VtIGFzIHNob3duIGluIHRoZSBzYW1wbGUgb3V0cHV0LiBUaGUgYXRvbXMgYXJlIGxpc3RlZCBpbiBsZXhpY29ncmFwaGljYWwgb3JkZXIsIGFuZCBhIGNvdW50IG9mIDEgaXMgaW1wbGllZCBhbmQgbm90IGV4cGxpY2l0bHkgd3JpdHRlbi4gVGhlcmUgYXJlIG5vIGJsYW5rIHNwYWNlcyBpbiB0aGUgb3V0cHV0LiBBbGwgb2YgdGhlIGNvdW50cyBpbiB0aGUgY29ycmVjdCBvdXRwdXQgd2lsbCBiZSByZXByZXNlbnRhYmxlIGluIDMyLWJpdCBzaWduZWQgaW50ZWdlcnMuPFwvcD5cclxuIiwiaGludCI6IiIsIm9yaWdpbmFsIjoiMSIsInByb2JsZW1fbGFuZ19jb2RlIjoiXHVjNjAxXHVjNWI0In1d

출처

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

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