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

【题意】

在这里输入题意

【题解】

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

【代码】

#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. Excel显示当前日期

    https://zhidao.baidu.com/question/431460329693825764.html 直接选中单元格,在公示栏输入=now()

  2. POJ 2133 暴搜

    题意: 思路: 按照题意暴搜 注意 如果目标串==给的串 答案是2 //By SiriurRen #include <cstdio> #include <cstring> #i ...

  3. deep-in-es6(六)

    箭头函数 Arrow Functions 箭头函数在JavaScript诞生是就存在,JavaScript建议在HTML注释内包裹行内脚本,这样可以避免不支持JS代码的浏览器将JS显示为文本. < ...

  4. Log4Net 用法记录

    https://www.cnblogs.com/lzrabbit/archive/2012/03/23/2413180.html https://blog.csdn.net/guyswj/articl ...

  5. 如何优雅的写UI——(6)内存泄漏

    控件讲了这么久,其实我的程序有两个Bug不知道大家有没有发现,这两个Bug都不会报错,对程序运行来说都没有阻碍,但是这种Bug对整个代码来说是一个很大的安全隐患. 什么是内存泄漏 内存泄漏(Memor ...

  6. [TypeScript] Restrict null and undefined via Non-Nullable-Types in TypeScript

    This lesson introduces the --strictNullChecks compiler option and explains how non-nullable types di ...

  7. 【UWP通用应用开发】控件、应用栏

    控件的属性.事件与样式资源 怎样加入控件 加入控件的方式有多种,大家更喜欢以下哪一种呢? 1)使用诸如Blend for Visual Studio或Microsoft Visual Studio X ...

  8. 微信小程序实现一个简单的表格

    wxml <view class="table"> <view class="tr bg-w"> <view class=&quo ...

  9. [Javascript AST] 4. Continue: Report ESLint error

    const disallowedMethods = ["log", "info", "warn", "error", & ...

  10. robot framework 使用三:浏览器兼容性自己主动化

    robot framework 測试浏览器兼容性 上图中黄色圈的地方默认什么都不写.是firefox浏览器,写上ie就是ie浏览器了 firefox最新版本号即可.ie须要设置: 1. IE选项设置的 ...