uvaoj1586Molar mass(暴力)
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(暴力)的更多相关文章
- CF911G Mass Change Queries(线段树+暴力)
cf机子真的快. 其实这个题的维护的信息还是很巧妙的. 首先,观察到题目中涉及到,区间修改这个操作,然后最后只查询一次,我们不妨用线段树来维护这个过程. 但是貌似直接维护每个位置的值可能不太好维护. ...
- [ACM_水题] ZOJ 3706 [Break Standard Weight 砝码拆分,可称质量种类,暴力]
The balance was the first mass measuring instrument invented. In its traditional form, it consists o ...
- 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 ...
- zone.js - 暴力之美
在ng2的开发过程中,Angular团队为我们带来了一个新的库 – zone.js.zone.js的设计灵感来源于Dart语言,它描述JavaScript执行过程的上下文,可以在异步任务之间进行持久性 ...
- 新手!mass 设置问题
mass就是你那个物体的质量啊质量越大,惯性也越大重力也越大.假如你的刚体的mass为1,那么你只要给这个物体9.81N向上的力,你就可以抵消重力,让这个物体悬浮着:但假如这个物体的mass为10,你 ...
- [bzoj3123][sdoi2013森林] (树上主席树+lca+并查集启发式合并+暴力重构森林)
Description Input 第一行包含一个正整数testcase,表示当前测试数据的测试点编号.保证1≤testcase≤20. 第二行包含三个整数N,M,T,分别表示节点数.初始边数.操作数 ...
- HDU 5944 Fxx and string(暴力/枚举)
传送门 Fxx and string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Othe ...
- 1250 Super Fast Fourier Transform(湘潭邀请赛 暴力 思维)
湘潭邀请赛的一题,名字叫"超级FFT"最终暴力就行,还是思维不够灵活,要吸取教训. 由于每组数据总量只有1e5这个级别,和不超过1e6,故先预处理再暴力即可. #include&l ...
- fragment+viepager 的简单暴力的切换方式
这里是自定义了一个方法来获取viewpager private static ViewPager viewPager; public static ViewPager getMyViewPager() ...
随机推荐
- VS 2013 scanf 报错问题
在VS2013 用C/C++编码时 使用scanf 会出现如下错误信息: 解决方法如下: 1. 在工程文件名出右击鼠标打开快捷菜单,找到“属性”选项,进入项目属性页面 2. 进入属性页面,找到“配置属 ...
- js 实现加入收藏/加入首页功能
加入收藏夹实现: html代码如下: <a href="javascript:;" onclick="AddFavorite(window.location.hre ...
- 【题解】洛谷P1351 [NOIP2014TG] 联合权值(树形结构+DFS)
题目来源:洛谷P1351 思路 由题意可得图为一棵树 在一棵树上距离为2的两个点有两种情况 当前点与其爷爷 当前点的两个儿子 当情况为当前点与其爷爷时比较好操作 只需要在传递时不仅传递父亲 还传递爷爷 ...
- 系统优化怎么做-JVM优化之开篇
大家好,这里是「聊聊系统优化 」,并在下列地址同步更新 博客园:http://www.cnblogs.com/changsong/ 知乎专栏:https://zhuanlan.zhihu.com/yo ...
- ios常用数据库、完美无缺
直接copy过去就能用,我们不用再去造轮子,现在的xocod9.4更加人性化了,不用再添加依赖库,这点苹果你让我开始喜欢了,哈哈. 需要这兄弟拉进去的哈 下班标的1,2,3,4就是就截图的4个文件,没 ...
- Enable directory listing on Nginx Web Server
1:Test environment [root@linux-node1 ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core ...
- jQuery基本toggle() toggleClass() 使用
今天来学习一下jQuery的基本函数的使用,很简单. 首先写一个button做控制按钮,然后写一个div用按钮控制idv做动画,从而测试JQuery的动画函数 <head> <met ...
- PHP的高效率写法
1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍. 当然了,这个测试方法需要在十万级以上次执行,效果才明显. 其实静态方法和非静态方法的 ...
- sublime解决gbk中文乱码包括Package Control: Install Package 无法使用
最近喜欢上了sublime,打算抛弃notepad,但是发现sublime居然不支持gbk编码,再上网查找资料之后,总结了一套解决方法,目前为止是行之有效的. 日期:2019年3月14日 第一步:到G ...
- C语言实现左旋字符串
#include<stdio.h> #include<stdlib.h> #include<string.h> void left_rotate(char *str ...