#include<stdio.h>
#include<string.h>
#include<ctype.h>
double getweight(char x)
{
double m=0;
switch(x){
case 'C':m=12.01;break;
case 'H':m=1.008;break;
case 'O':m=16.00;break;
case 'N':m=14.01;break;
}
return m;
} int main()
{
int T;
scanf("%d",&T);
while(T--){
char s[100];
scanf("%s",s);
int i;
double t = 0;
int len = strlen(s);
for(i = 0;i < len;i++){
if(isalpha(s[i]) && isdigit(s[i + 1]) && isdigit(s[i + 2]))
t += getweight(s[i])*((s[i+1]-'0')*10 + (s[i + 2]-'0'));
else if(isalpha(s[i]) && isdigit(s[i + 1]))
t += getweight(s[i])*(s[i+1] -'0');
else if(isalpha(s[i]) && (!isdigit(s[i+1])))
t += getweight(s[i]);
}
printf("%.3f\n",t);
t = 0;
}
return 0;
}

1.字符串中的数字要减去0才可以计算

习题3-2 分子量(Molar Mass, ACM/ICPC Seoul 2007, UVa1586)的更多相关文章

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

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

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

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

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

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

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

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

  5. [C++]环状序列(CircularSequence,ACM/ICPC Seoul 2004,UVa1584)

    Question 例题3-5 环状序列(CircularSequence,ACM/ICPC Seoul 2004,UVa1584) 长度为n的环状串有n种表示方法,分别为从某个位置开始顺时针得到,在这 ...

  6. [C++]最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583)

    Question 例题3-5 最小生成元 (Digit Generator, ACM/ICPC Seoul 2005, UVa1583) 如果x+x的各个数字之和得到y,就是说x是y的生成元.给出n( ...

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

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

  8. 习题3-5 谜题(Puzzle, ACM/ICPC World Finals 1993, UVa227)

    #include<stdio.h> #include<string.h> char s[5][5]; int main() { while(gets(s[0])) { int ...

  9. 习题3-3 数数字(Digit Counting , ACM/ICPC Danang 2007, UVa1225)

    #include<stdio.h> #include<string.h> int main() { char s[100]; scanf("%s",s); ...

随机推荐

  1. PostgressQL

    环境 ubuntu18.04 docker 中 pull postgres:10 images 连接 进入容器内部 docker exec -it [mypostgres] /bin/bash 查看p ...

  2. TP6.0多应用模式隐藏路由中的应用名

    本文默认采用的是多应用模式 PHP技术群: 159789818 ThinkPHP技术群: 828567087 1. 多应用模式中隐藏路由中的应用名的三种方式 域名绑定应用 增加应用入口 入口文件绑定应 ...

  3. ui自动化--鼠标操作ActionChains

    需要先引入鼠标操作模块:from selenium.webdriver.common.action_chains import ActionChains 实际上ActionChains这个模块的实现的 ...

  4. html基础:DOM操作

    DOM(Document Object Model 文档对象模型) 一个web页面被封装成一个dom对象,通过dom中的js对页面的标签进行操作 一.获取对象 浏览器页面上右键--检查--consol ...

  5. ParticleSystem的小优化

    最近游戏场景希望加入一些ParticleSystem来丰富场景,这样肯定会带来一定的性能开销.一般来说ParticleSystem的优化就是尽量减少粒子数,尽量不使用粒子碰撞等.而今天要说的是,多个P ...

  6. oracle之复杂查询之一:多表连接技术

    复杂查询之一:多表连接技术 7.1 简单查询的解析方法: 全表扫描:指针从第一条记录开始,依次逐行处理,直到最后一条记录结束: 横向选择+纵向投影=结果集 7.2 多表连接 交叉连接(笛卡尔积) 非等 ...

  7. 学习go的一些笔记

    反射 reflect type CfgSt struct{ Match *int64 `ini:"match"` Desc string `ini:"desc" ...

  8. 深度神经网络conda环境下载

    介绍 因为使用conda下载数据有时候因为网络问题下载非常慢,因此我把conda的环境备份好,到时可以直接使用conda的conda create -n 新环境名字 –clone 环境的路径 , 直接 ...

  9. openstack核心组件——cinder存储服务(11)

    一.cinder 介绍:   理解 Block Storage 操作系统获得存储空间的方式一般有两种: 通过某种协议(SAS,SCSI,SAN,iSCSI 等)挂接裸硬盘,然后分区.格式化.创建文件系 ...

  10. 编译 lua cjson模块

    使用文档:http://www.kyne.com.au/~mark/software/lua-cjson-manual.html下载地址:http://www.kyne.com.au/%7Emark/ ...