zoukankan      html  css  js  c++  java
  • HDU 5949 Relative atomic mass 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    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



    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
     
    Source
     
    Recommend
    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[N];
    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
    ",ans);
    65     }
    66     return 0;
    67 }
    68 /*
    69 //
    70 
    71 //
    72 */
    View Code
  • 相关阅读:
    图片特效大杀器--swiper.js
    降低手机网错误率
    前端加sentry错误监控
    一些常识
    github/gitlab ssh-key公钥各种问题 解决
    移动端非常规bug
    sublime text3 高效插件及常用快捷键
    HTML5实现video标签的皮肤自定义
    C端产品前端工程管理
    利用BFS广度优先搜索,搜索字母矩阵中的单词
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/6015908.html
Copyright © 2011-2022 走看看