简单的化学式  求分子量问题 下面附上  代码和解析.

 #include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std ;
int main()
{
double l,m,n,t,sum,w;
int i,q;
char a[];
scanf("%lf",&t);
while(t--)
{
w=m=;
scanf("%s",a);
l=strlen(a);
for(sum=i=;i<l;i++)
{
q=n=;
if(!(a[i]-''>=&&a[i]-''<=)) //当 这次不是数字 越界的时候 也不是数字哦.
{
if(a[i]=='C')
m=12.01;
else
if(a[i]=='H')
m=1.008;
else
if(a[i]=='O')
m=;
else
if(a[i]='N')
m=14.01;
n=; //用于处理 当这个化学元素没有后缀时的情况
}
if(a[i+]-''>=&&a[i+]-''<=) //有后缀时.
{
i++;
n=;
while(a[i]-''>=&&a[i]-''<=)
{
n=n*pow(,q)+(a[i]-'');
q++;
if(!(a[i+]-''>=&&a[i+]-''<=))
break;
i++;
}
}
sum=sum+m*n;
}
printf("%.3lf\n",sum);
}
return ;
}

课后题--------求分子量-----Molar mass------的更多相关文章

  1. 【OI】计算分子量 Molar mass UVa 1586 题解

    题目:(由于UVa注册不了,还是用vjudge) https://vjudge.net/problem/UVA-1586 详细说明放在了注释里面.原创. 破题点在于对于一个元素的组合(元素+个数),只 ...

  2. 分子量(Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)

    #include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ char s[20]; scanf ...

  3. UVa 1586 Molar mass --- 水题

    UVa 1586 题目大意:给出一种物质的分子式(不带括号),求分子量.本题中分子式只包含4种原子,分别为C.H.O.N, 原子量分别为12.01,1.008,16.00,14.01 解题思路:先实现 ...

  4. 分子量 (Molar Mass,ACM/ICPC Seoul 2005,UVa1586)

    习题 3-3 分子量 (Molar Mass,ACM/ICPC Seoul 2005,UVa1586) 给出一种物质的分子式(不带括号),求分子量.本题中的分子式只包含4种原子,分别为C,H,O,N, ...

  5. 玉伯的一道课后题题解(关于 IEEE 754 双精度浮点型精度损失)

    前文 的最后给出了玉伯的一道课后题,今天我们来讲讲这题的思路. 题目是这样的: Number.MAX_VALUE + 1 == Number.MAX_VALUE; Number.MAX_VALUE + ...

  6. Molar mass UVA - 1586

    ​ An organic compound is any member of a large class of chemical compounds whose molecules contain c ...

  7. 算法(JAVA)----两道小小课后题

    LZ最近翻了翻JAVA版的数据结构与算法,无聊之下将书中的课后题一一给做了一遍,在此给出书中课后题的答案(非标准答案,是LZ的答案,猿友们可以贡献出自己更快的算法). 1.编写一个程序解决选择问题.令 ...

  8. 课后题2.87&2.86

    课后题2.86&2.87 单纯就是想加点分第十章的题目都被做过了就做下第二章的,正好复习一下前面学的知识,第二章给我剩下的题目也不多了,我就挑了这个题目. 2.86 考虑一个基于IEEE浮点格 ...

  9. c++面向对象程序设计 课后题 答案 谭浩强 第四章

    c++面向对象程序设计课后题答案 谭浩强 第四章 1: #include <iostream> using namespace std; class Complex {public: Co ...

随机推荐

  1. iOS点击cell时,控件背景色消失的解决方法

    同时调用一下两个方法: - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected ...

  2. transaction transaction transaction 最大费用最大流转化到SPFA最长路

    //当时比赛的时候没有想到可以用SPFA做,TLE! Problem Description Kelukin is a businessman. Every day, he travels aroun ...

  3. 【进击后端】Ubuntu 命令行 安装nginx

    一.安装nginx apt-get install nginx 安装路径为:/etc/nginx/conf.d 二.配置nginx,在conf.d目录下新建test.conf 新建文件的命令是vi t ...

  4. Word Search(深度搜索DFS,参考)

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...

  5. SecureCRT在Tab下的Title显示IP

    注意:要针对每个Session进行修改才行. 参考: http://www.cnblogs.com/tyhmj/archive/2013/12/20/3483247.html

  6. Servlet的HelloWorld实例

    以下内容引用自http://wiki.jikexueyuan.com/project/servlet/first-example.html: Servlets是Java类,服务于HTTP请求并实现了j ...

  7. 怎样把UCos-ii_在STM32上的移植

    下载代码 stm32 标准外设库是 stm32 全系列芯片的外设驱动,有了它能够大大加速我们 开发 stm32. 首先从 st 公司的站点下载最新的 stm32 标准外设库,写本文时最新的版本号是 V ...

  8. 013 IPv6

    Router>en Router#config t Enter configuration commands, one per line.  End with CNTL/Z. Router(co ...

  9. 【C++/数据结构】单链表的基本操作

    #pragma once #ifndef _CLIST_H_ #define _CLIST_H_ #include <iostream> #include <assert.h> ...

  10. java中关于'&&'、'||'混合运算优先级问题小结

    package com.per.sdg.operator; /** * 结论:先进行'&&'运算,在进行'||'运算 * @author sundg * */ public class ...