博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【OI】计算分子量 Molar mass UVa 1586 题解
阅读量:5478 次
发布时间:2019-06-16

本文共 968 字,大约阅读时间需要 3 分钟。

题目:(由于UVa注册不了,还是用vjudge)

详细说明放在了注释里面。原创。

破题点在于对于一个元素的组合(元素+个数),只有3种可能:

1、单个元素

2、一个元素和一位数字

3、一个元素和两位数字

没有了。因为题设交代了n<=99,表明个数只能为2位数。分别判断即可。

/*Copyright 2019 AlexanderZ.TangMolar_mass.cppFor UVa 1586https://cnblogs.cn/nowonder*/#include 
#include
#include
const int num[] = {
0,1,2,3,4,5,6,7,8,9}; //使用数组将字符数字转为数字,ch - '0'即为该数字的下标 char s[80]; //储存字符串,n<=80 double get_mass(char ch){ //获得对应字符的分子量 if (ch=='C') return 12.01; if (ch=='H') return 1.008; if (ch=='O') return 16.00; if (ch=='N') return 14.01;}int main(){ int T; double sum; scanf("%d",&T); while (T--) //计数器 { sum = 0; scanf("%s",s); int len = strlen(s); if (len < 2) //对于单个字符,直接输出,否则造成溢出 { printf("%.3lf\n",get_mass(s[0])); continue; } for (int i=0;i

 

转载于:https://www.cnblogs.com/nowonder/p/Molar_mass.html

你可能感兴趣的文章
layer弹出层的关闭问题
查看>>
LeetCode——3Sum &amp; 3Sum Closest
查看>>
netstat详解
查看>>
微信小程序 --- e.currentTarget.dataset.id 获取不到值
查看>>
Introducing stapbpf – SystemTap’s new BPF backend
查看>>
详细介绍MySQL/MariaDB的锁
查看>>
0603-Zuul构建API Gateway-通过Zuul上传文件,禁用Zuul的Filter
查看>>
cocos2dx-2.x CCFileUtils文件管理分析(2)
查看>>
Emacs中多个golang项目的配置方法
查看>>
未知宽高div水平垂直居中3种方法
查看>>
Vim替换查找
查看>>
如何用sysbench做好IO性能测试
查看>>
利用线性回归模型进行卫星轨道预报
查看>>
懒加载和预加载
查看>>
前端面试题
查看>>
Python的赋值、浅拷贝、深拷贝
查看>>
用python操作mysql数据库(之代码归类)
查看>>
centos安装iftop监控服务器流量
查看>>
ArcGIS Server 10.1 SP1连续查询出现Unable to complete operation错误
查看>>
执行./configure报checking for g++... no错误
查看>>