您的位置:首页 > 其它

HDU 5949 Relative atomic mass 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

2016-10-31 15:03 567 查看


Relative atomic mass

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 66 Accepted Submission(s): 59

[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
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.

[align=left]Output[/align]
For each molecule, output its relative atomic mass.

[align=left]Sample Input[/align]

5
H
C
O
HOH
CHHHCHHOH

[align=left]Sample Output[/align]

1
12
16
18
46

[align=left]Source[/align]
2016ACM/ICPC亚洲区沈阳站-重现赛(感谢东北大学)

[align=left]Recommend[/align]
jiangzijing2015 | We have carefully selected several similar problems for you: 5960 5959 5958 5957 5956

Statistic | Submit | Discuss | Note



题目链接:

  http://acm.hdu.edu.cn/showproblem.php?pid=5949


题目大意:

  给一个只含C H O的分子式,求相对分子质量。

题目思路:

  【模拟】

  水题,直接模拟即可。

1 //
2 //by coolxxx
3 //#include<bits/stdc++.h>
4 #include<iostream>
5 #include<algorithm>
6 #include<string>
7 #include<iomanip>
8 #include<map>
9 #include<stack>
10 #include<queue>
11 #include<set>
12 #include<bitset>
13 #include<memory.h>
14 #include<time.h>
15 #include<stdio.h>
16 #include<stdlib.h>
17 #include<string.h>
18 //#include<stdbool.h>
19 #include<math.h>
20 #pragma comment(linker,"/STACK:1024000000,1024000000")
21 #define min(a,b) ((a)<(b)?(a):(b))
22 #define max(a,b) ((a)>(b)?(a):(b))
23 #define abs(a) ((a)>0?(a):(-(a)))
24 #define lowbit(a) (a&(-a))
25 #define sqr(a) ((a)*(a))
26 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
27 #define mem(a,b) memset(a,b,sizeof(a))
28 #define eps (1e-8)
29 #define J 10000
30 #define mod 1000000007
31 #define MAX 0x7f7f7f7f
32 #define PI 3.14159265358979323
33 #define N 24
34 #define M 1004
35 using namespace std;
36 typedef long long LL;
37 double anss;
38 LL aans;
39 int cas,cass;
40 int n,m,lll,ans;
41 char s
;
42 int main()
43 {
44     #ifndef ONLINE_JUDGE
45     freopen("1.txt","r",stdin);
46 //    freopen("2.txt","w",stdout);
47     #endif
48     int i,j,k;
49     int x,y,z;
50 //    init();
51     for(scanf("%d",&cass);cass;cass--)
52 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
53 //    while(~scanf("%s",s))
54 //    while(~scanf("%d%d",&n,&m))
55     {
56         scanf("%s",s);
57         n=strlen(s);ans=0;
58         for(i=0;i<n;i++)
59         {
60             if(s[i]=='H')ans++;
61             else if(s[i]=='O')ans+=16;
62             else if(s[i]=='C')ans+=12;
63         }
64         printf("%d\n",ans);
65     }
66     return 0;
67 }
68 /*
69 //
70
71 //
72 */


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: