【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

模拟.
主要是找那个数字。

【代码】

#include <bits/stdc++.h>
using namespace std; double dic[300]; int main()
{
/*freopen("F:\\rush.txt", "r", stdin);*/
int T;
scanf("%d", &T);
dic['C'] = 12.01;
dic['H'] = 1.008;
dic['O'] = 16.00;
dic['N'] = 14.01;
while (T--)
{
string s;
cin >> s;
double ans = 0;
int len = s.size();
for (int i = 0; i < len; i++)
if (i+1>=len || isalpha(s[i+1]))
{
ans += dic[s[i]];
}
else
{
int j = (i + 1);
while (j + 1 < len && isdigit(s[j + 1])) j++;
int num = 0;
for (int k = i + 1; k <= j; k++)
num = num * 10 + s[k] - '0';
ans += 1.0*dic[s[i]] * num;
i = j;
}
printf("%.3f\n", ans);
}
return 0;
}

【习题 3-2 UVA - 1586】Molar mass的更多相关文章

  1. UVa 1586 Molar mass --- 水题

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

  2. UVa 1586 Molar mass

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

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

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

  4. uva 1586 Molar mass(Uva-1586)

    这题做的相当的复杂...之前做的现在应该能简单一点了写的. 我的代码: #include <bits/stdc++.h> using namespace std; main() { int ...

  5. 习题3-2 分子量(Molar Mass, ACM/ICPC Seoul 2007, UVa1586)

    #include<stdio.h> #include<string.h> #include<ctype.h> double getweight(char x) { ...

  6. Molar mass UVA - 1586

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

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

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

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

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

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

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

随机推荐

  1. js---16继承

    123 instanceof Number;//false,要左边是对象右边是函数 typeof 123 ; //number new Number(123) instanceof Number; / ...

  2. POJ 3039 搜索??? (逼近)

    思路: 抄的题解 这叫搜索? 难以理解 我觉得就是枚举+逼近 //By SiriusRen #include <cmath> #include <cstdio> #includ ...

  3. Elasticsearch之shield(权限)插件安装之后的浏览详解

    前期博客 Elasticsearch-2.4.3的3节点安装(多种方式图文详解)(含 head.kopf.marvel.shield和watcher插件安装和使用) 访问es:-u es_admin ...

  4. recyclerview23+出现多个item只显示第一个item的问题

    1.改成21+可以,如果不行,就使用第2或第3个解决方案 2.对每个item的inflate,传入两个参数,第二个参数设置为null,而不是使用3个参数(第二个parent,第三个false) 3.i ...

  5. Kinect 开发 —— 骨骼数据与彩色影像和深度影像的对齐

    在显示彩色影像和深度影像时最好使用WriteableBitmap对象: 要想将骨骼数据影像和深度影像,或者彩色影像叠加到一起,首先要确定深度影像的分辨率和大小,为了方便,这里将深度影像数据和彩色影像数 ...

  6. Gym 100952 H. Special Palindrome

    http://codeforces.com/gym/100952/problem/H H. Special Palindrome time limit per test 1 second memory ...

  7. WebService 获取客户端 IP 和 MAC 等信息

    IP地址 public string getClientIP() { string result = HttpContext.Current.Request.ServerVariables[" ...

  8. Flume的可管理性

    Flume的可管理性  所有agent和Collector由master统一管理,这使得系统便于维护. 多master情况,Flume利用 ZooKeeper和gossip,保证动态配置数据的一致性. ...

  9. jQuery自定义插件规范

    <ul class="list"> <li>导航列表 <ul class="nav"> <li>导航列表1< ...

  10. HDU 2333 Assemble(二分)

    Assemble Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...