An organic compound is any member of a large class of chemical
compounds whose molecules contain carbon. The molar
mass of an organic compound is the mass of one mole of the
organic compound. The molar mass of an organic compound
can be computed from the standard atomic weights of the
elements.
When an organic compound is given as a molecular formula,
Dr. CHON wants to find its molar mass. A molecular
formula, such as C3H4O3, identifies each constituent element by
its chemical symbol and indicates the number of atoms of each
element found in each discrete molecule of that compound. If
a molecule contains more than one atom of a particular element,
this quantity is indicated using a subscript after the chemical symbol.
In this problem, we assume that the molecular formula is represented by only four elements, ‘C’
(Carbon), ‘H’ (Hydrogen), ‘O’ (Oxygen), and ‘N’ (Nitrogen) without parentheses.
The following table shows that the standard atomic weights for ‘C’, ‘H’, ‘O’, and ‘N’.
Atomic Name Carbon Hydrogen Oxygen Nitrogen
Standard Atomic Weight 12.01 g/mol 1.008 g/mol 16.00 g/mol 14.01 g/mol
For example, the molar mass of a molecular formula C6H5OH is 94.108 g/mol which is computed by
6 × (12.01 g/mol) + 6 × (1.008 g/mol) + 1 × (16.00 g/mol).
Given a molecular formula, write a program to compute the molar mass of the formula.
Input
Your program is to read from standard input. The input consists of T test cases. The number of test
cases T is given in the first line of the input. Each test case is given in a single line, which contains
a molecular formula as a string. The chemical symbol is given by a capital letter and the length of
the string is greater than 0 and less than 80. The quantity number n which is represented after the
chemical symbol would be omitted when the number is 1 (2 ≤ n ≤ 99).
Output
Your program is to write to standard output. Print exactly one line for each test case. The line should
contain the molar mass of the given molecular formula.
Sample Input
4
C
C6H5OH
NH2CH2COOH
C12H22O11
Sample Output
12.010
94.108
75.070
342.296

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4461

题意:给出一个分子式,要求计算分子量,纯暴力

 #include<bits/stdc++.h>
using namespace std;
char s[];
int main() {
int t;
scanf("%d",&t);
while(t--)
{
memset(s,'\0',sizeof(s));
scanf("%s",s);double ans=;
for(int i=;i<strlen(s);i++)
{
if(s[i]=='C')
{
if(s[i+]>=&&s[i+]<=&&(s[i+]<||s[i+]>))
{
ans+=12.01*(s[i+]-);
}else if(s[i+]>=&&s[i+]<=&&s[i+]>=&&s[i+]<=)
{
ans+=12.01*((s[i+]-)*+(s[i+]-));
}else
{
ans+=12.01;
}
}else if(s[i]=='H')
{
if(s[i+]>=&&s[i+]<=&&(s[i+]<||s[i+]>))
{
ans+=1.008*(s[i+]-);
}else if(s[i+]>=&&s[i+]<=&&s[i+]>=&&s[i+]<=)
{
ans+=1.008*((s[i+]-)*+(s[i+]-));
}else
{
ans+=1.008;
}
}else if(s[i]=='O')
{
if(s[i+]>=&&s[i+]<=&&(s[i+]<||s[i+]>))
{
ans+=16.00*(s[i+]-);
}else if(s[i+]>=&&s[i+]<=&&s[i+]>=&&s[i+]<=)
{
ans+=16.00*((s[i+]-)*+(s[i+]-));
}else
{
ans+=16.00;
}
}else if(s[i]=='N')
{
if(s[i+]>=&&s[i+]<=&&(s[i+]<||s[i+]>))
{
ans+=14.01*(s[i+]-);
}else if(s[i+]>=&&s[i+]<=&&s[i+]>=&&s[i+]<=)
{
ans+=14.01*((s[i+]-)*+(s[i+]-));
}else
{
ans+=14.01;
}
}
}
printf("%.3lf\n",ans);
}
return ;
}

uvaoj1586Molar mass(暴力)的更多相关文章

  1. CF911G Mass Change Queries(线段树+暴力)

    cf机子真的快. 其实这个题的维护的信息还是很巧妙的. 首先,观察到题目中涉及到,区间修改这个操作,然后最后只查询一次,我们不妨用线段树来维护这个过程. 但是貌似直接维护每个位置的值可能不太好维护. ...

  2. [ACM_水题] ZOJ 3706 [Break Standard Weight 砝码拆分,可称质量种类,暴力]

    The balance was the first mass measuring instrument invented. In its traditional form, it consists o ...

  3. USACO 1.3 Ski Course Design - 暴力

    Ski Course Design Farmer John has N hills on his farm (1 <= N <= 1,000), each with an integer ...

  4. zone.js - 暴力之美

    在ng2的开发过程中,Angular团队为我们带来了一个新的库 – zone.js.zone.js的设计灵感来源于Dart语言,它描述JavaScript执行过程的上下文,可以在异步任务之间进行持久性 ...

  5. 新手!mass 设置问题

    mass就是你那个物体的质量啊质量越大,惯性也越大重力也越大.假如你的刚体的mass为1,那么你只要给这个物体9.81N向上的力,你就可以抵消重力,让这个物体悬浮着:但假如这个物体的mass为10,你 ...

  6. [bzoj3123][sdoi2013森林] (树上主席树+lca+并查集启发式合并+暴力重构森林)

    Description Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M,T,分别表示节点数.初始边数.操作数 ...

  7. HDU 5944 Fxx and string(暴力/枚举)

    传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Othe ...

  8. 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)

    湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...

  9. fragment+viepager 的简单暴力的切换方式

    这里是自定义了一个方法来获取viewpager private static ViewPager viewPager; public static ViewPager getMyViewPager() ...

随机推荐

  1. 开源项目之kisso

    kisso开源项目:https://gitee.com/baomidou/kisso 一.简介 kisso  =  cookie sso 基于 Cookie 的 SSO 中间件,它是一把快速开发 ja ...

  2. 面试准备——(二)专业知识(1)Linux

    面试的问题: 腾讯: 1. 查看进程的命令 美团: 1. 常用的命令——美团/滴滴 2. 如何在性能测试的时候查看进程 3. kill -9/-15区别 滴滴: 1.如何找到一个特定文件 2. 如何替 ...

  3. iview(DatePicker)时间转入后台少一天 解决方案

    后台注解 前台: 加个事件 @on-change @on-change="getStartTime" getStartTime(starTime) { this.leaveReco ...

  4. P2916 [USACO08NOV]安慰奶牛Cheering up the Cow

    往奶牛里打气 题目评级不难. 感觉思路有值得借鉴的地方.(虽然少,毕竟积沙成塔吗qwq) 很容易看出来,是要求最小生成树的. 然后生成树的计算方式不一样. 我们考虑拼接(感觉大部分oi都可以使用类似的 ...

  5. 如何不使用 submit 按钮来提交表单?

      如果我们不想用 submit 按钮来提交表单,我们也可以用超链接来提交,我们可以这样写代码: <a href=”javascript: document.myform.submit ();” ...

  6. react系列(五)在React中使用Redux

    上一篇展示了Redux的基本使用,可以看到Redux非常简单易用,不限于React,也可以在Angular.Vue等框架中使用,只要需要Redux的设计思想的地方,就可以使用它. 这篇主要讲解在Rea ...

  7. 使用dbca命令静默卸载数据库

    1)     help查询dbca的选项 su - oracledbca -help dbca [-silent | -progressOnly | -customCreate] {<comma ...

  8. 20181029NOIP模拟赛T2

    2.追捕 [题目背景] Duan2baka:“jmsyzsfq天下第一蠢!” jmsyzsfq:“你说什么?!” [题目描述] 于是Duan2baka开始了逃亡的旅程,而jmsyzsfq也开始追捕Du ...

  9. 抓包之Charles For Mac 4.0+破解版

    前言:突然间发现好久没有写博客了,最近被公司的项目弄得脑壳疼

  10. 编写radware的负载配置

    radware如何添加负载服务? 笔者在新添加radware的新负载服务的时候,是习惯去看下上一个负载服务的ID 和 节点服务的ID 号 分别是多少,主要是避免ID冲突,把其他服务顶替下去,同时以后这 ...