시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 64 MB 14 9 9 64.286%

문제

우리 몸은 생물학적 작용에 필수적인 역할을 하는 단백질로 구성되어 있다. 이 단백질을 건물이라고 한다면 아미노산은 이 건물의 벽돌과 같다. 우리 몸의 근육과 세포 조직 대부분이 아미노산으로 이루어져 있어 세포를 조직화 하는 등의 신체적으로 중요한 기능들을 수행한다. 아미노산의 핵심 원소는 탄소(C), 수소(H), 산소(O), 질소(N), 그리고 황(S)이다.

주어진 아미노산의 화학식을 통하여 분자량을 계산하는 프로그램을 만들어보자.

예를 들어, 알라닌(Alanine)의 화학식은 O2C3NH7이고, 산소 2개, 탄소 3개, 질소 1개, 수소 7개를 가지고 있다. 

  • 산소 15.9994
  • 탄소 12.011
  • 수소 1.00794
  • 황 32.066
  • 질소 14.00674

각 원소에 대한 원자량이 주어졌을 때, 알라닌의 분자량은 다음과 같이 계산할 수 있다.

(알라닌의 분자량) = 2x15.9994 + 3x12.011 + 1x14.00674 +7x1.00794 = 89.09412

같은 방법으로, 메티오닌(C5H11NO2S)의 분자량은 149.213880 이 된다.

입력

입력의 첫 줄에 테스트 케이스의 개수인 정수 n(1<= n <= 100)이 주어진다. 그리고 둘째 줄 부터 아미노산의 화학식을 나타내는 n개의 문자열이 한 줄씩 주어진다. 화학식은 앞에서 언급한 원소를 나타내는 다섯 개의 영문자와, 그에 대응하는 원소의 개수를 나타내는 숫자로 구성되어 있다. 각각의 화학식은 100자 미만이다.

출력

각각의 아미노산의 분자량을 출력한다. 화학식에 아미노산을 이루는 필수 원소가 아닌 문자가 포함되어 있다면 "Invalid formula"를 출력한다. 분자량은 소숫점 아래 4자리의 실수로 출력한다.

예제 입력 1

6
S
O2C3NH7
C2H5NO2
C5H11NO2S
C6N14N2O2
OX

예제 출력 1

32.0660
89.0941
75.0672
149.2139
328.1726
Invalid formula
W3sicHJvYmxlbV9pZCI6IjEwMjk5IiwicHJvYmxlbV9sYW5nIjoiMCIsInRpdGxlIjoiX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