2016年ICPC中国大陆区域赛(沈阳)B题

题目网址点击进入

Problem Description
Relative atomic mass is a dimensionless physical quantity, the ratio of the average mass of atoms of an element (from a single given sample or source) to 12of the mass of an atom of carbon-12 (known as the unified atomic mass unit).
You need to calculate the relative atomic mass of a molecule, which consists of one or several atoms. In this problem, you only need to process molecules which contain hydrogen atoms, oxygen atoms, and carbon atoms. These three types of atom are written as ’H’,’O’ and ’C’ repectively. For your information, the relative atomic mass of one hydrogen atom is 1, and the relative atomic mass of one oxygen atom is 16 and the relative atomic mass of one carbon atom is 12. A molecule is demonstrated as a string, of which each letter is for an atom. For example, a molecule ’HOH’ contains two hydrogen atoms and one oxygen atom, therefore its relative atomic mass is 18 = 2 * 1 + 16.

Input
The first line of input contains one integer N(N ≤ 10), the number of molecules. In the next N lines, the i-th line contains a string, describing the i-th molecule. The length of each string would not exceed 10.

Output
For each molecule, output its relative atomic mass.

Sample Input
5
H
C
O
HOH
CHHHCHHOH

Sample Output
1
12
16
18
46

大致题意:
给出一个 t 接下来 t 组,每行给出一个不大于10的字符串,一个H等于1,一个C等于12,一个O等于16,求字符串总和

思路
依旧水题

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long int LLD;
int main()
{
    LLD t;
    scanf("%lld%*c",&t);
    while (t--)
    {
        LLD ans=0;
        char c;
        while (scanf("%c",&c)&&c!='\n')
        {
            if (c=='H')
            {
                ans+=1;
            }else if (c=='C')
            {
                ans+=12;
            }else if (c=='O')
            {
                ans+=16;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

发布了27 篇原创文章 · 获赞 4 · 访问量 4416

猜你喜欢

转载自blog.csdn.net/qq_43735840/article/details/104348093