这题做的相当的复杂。。。之前做的现在应该能简单一点了写的。

我的代码:

#include <bits/stdc++.h>
using namespace std;
main()
{
int a;
cin>>a;
while(a--)
{
string b="";
cin>>b;
stringstream stream;
int sumc,sumh,sumo,sumn;
sumc=sumh=sumo=sumn=;
int c,h,o,n,f;
c=h=o=n=;f=;
string str="";
for(int i=;i<b.size()+;i++)
{
if(isalpha(b[i])&&isalpha(b[i+])||isalpha(b[i])&&!b[i+])
{
if(b[i]=='C')
sumc+=;
if(b[i]=='H')
sumh+=;
if(b[i]=='O')
sumo+=;
if(b[i]=='N')
sumn+=;
}
else if(isdigit(b[i])&&f)
{
if(b[i-]=='C')
{
str+=b[i];c=;f=;
}
if(b[i-]=='H')
{
str+=b[i];h=;f=;
}
if(b[i-]=='O')
{
str+=b[i];o=;f=;
}
if(b[i-]=='N')
{
str+=b[i];n=;f=;
}
}
else if(c&&!f)
{
if(isalpha(b[i])||!b[i])
{
int num=;
f=;c=;
stream<<str;
stream>>num;
sumc+=num;
stream.clear();
str="";
}
else
str+=b[i];
}
else if(h&&!f)
{
if(isalpha(b[i])||!b[i])
{
int num=;
f=;h=;
stream<<str;
stream>>num;
sumh+=num;
stream.clear();
str="";
}
else
str+=b[i];
}
else if(o&&!f)
{
if(isalpha(b[i])||!b[i])
{
int num=;
f=;o=;
stream<<str;
stream>>num;
sumo+=num;
stream.clear();
str="";
}
else
str+=b[i];
}
else if(n&&!f)
{
if(isalpha(b[i])||!b[i])
{
int num=;
f=;n=;
stream<<str;
stream>>num;
sumn+=num;
stream.clear();
str="";
}
else
str+=b[i];
}
}
double sum=;
sum=sumc*12.01+sumh*1.008+sumo*16.00+sumn*14.01;
printf("%.3lf\n",sum);
}
}

uva 1586 Molar mass(Uva-1586)的更多相关文章

  1. UVa 1586 Molar mass --- 水题

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

  2. Molar mass UVA - 1586

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

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

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

  4. UVa 1586 Molar mass

    题意:给出物质的分子式,计算它的相对原子质量 因为原子的个数是在2到99之间的,所以找出一个是字母之后,再判断一下它的后两位就可以找出这种原子的个数了 #include<iostream> ...

  5. UVa 1586 - Molar Mass - ACM/ICPC Seoul 2007 - C语言

    关键在于判断数字是两位数还是单位数,其他部分没有难度. #include"stdio.h" #include"string.h" #include"c ...

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

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

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

    解题思路: 1.将分子量用double 数组记录下来 2.将字符串存储在字符数组中,从头向后扫描,一直记住“字母”,对下一个字符进行判断,是否是数字,如果是数字:用一个整数记录,本代码中用的sum,同 ...

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

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

  9. 【习题 3-2 UVA - 1586】Molar mass

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟. 主要是找那个数字. [代码] #include <bits/stdc++.h> using namespace ...

随机推荐

  1. 第14章4节《MonkeyRunner源代码剖析》 HierarchyViewer实现原理-装备ViewServer-port转发

    在初始化HierarchyViewer的实例过程中,HierarchyViewer会调用自己的成员方法setupViewServer来把ViewServer装备好,那么我们这里先看下这种方法: 39 ...

  2. python 文档生成 字符串替换

    替换 fnr, fnr_source, fnw = 'my.py.html', '产品清单.txt', 'my.py.res.html'd_source = {}with open(fnr_sourc ...

  3. Linux中grep命令的12个实践例子

    grep是每个Linux发行版都预装的一个强有力的文件模式搜索工具.无论何种原因,如果你的系统没有预装它的话,你可以很容易的通过系统的包管理器来安装它(Debian/Ubuntu系中的apt-get和 ...

  4. dotnet core 文档链接

    The installation was successful The following were installed at C:\Program Files\dotnet • .NET Core ...

  5. codeforces 939E Maximize! 双指针(two pointers)

    E. Maximize! time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  6. 洛谷 P3398 仓鼠找sugar —— 树链剖分

    题目:https://www.luogu.org/problemnew/show/P3398 树链剖分一下,路径就变成线段树上的几个区间: 两条路径相交就是线段树上有区间相交,所以在相应位置打个标记, ...

  7. 在eclipse中如何在大量项目中查找指定文件(转载)

    转载:http://blog.csdn.net/inowcome/article/details/6699227 在eclipse中如果希望在大量的项目中寻找指定的文件可不是一件轻松的事,还好ecli ...

  8. Django-CKeditor使用笔记

    1. 安装django-ckeditor $ pip install django-ckeditor 2. 在setting中,添加ckeditor , ckeditor_uploader 到INST ...

  9. Rails 服务器架设失败问题

    更新: 2017/09/14 补充了简单的确认号码的方法 A server is already running. Check /Users/...../pids/server.pid. Exitin ...

  10. Django day26 初识认证组件

    一:什么是认证组件 只有认证通过的用户才能访问指定的url地址,比如:查询课程信息,需要登录之后才能查看,没有登录,就不能查看,这时候需要用到认证组件 二:认证组件源码分析