chaper3_exerise_Uva1568_Molar_Mass_分子量
#include<iostream>
#include<iomanip>
#include<string>
#include<cctype>
using namespace std;
const int maxn = ; void get_num(int &num,string c,int j)
{
while (isdigit(c[j]) && c[j])
{
num = num* + (c[j]-'');
j++;
}
} int main(void)
{
string c;
int T;
cin >> T;
for (int i = ; i < T; i++)
{
double count = ;
cin >> c;
for (int j = ; j < c.size(); j++)
{
if (isalpha(c[j]))
{
if (isdigit(c[j+]))
{
int num = ;
get_num(num,c,j+);
switch(c[j])
{
case 'C' : count += 12.01*num; break;
case 'H' : count += 1.008*num; break;
case 'O' : count += 16.00*num; break;
case 'N' : count += 14.01*num; break;
}
}
else {
switch(c[j])
{
case 'C' : count += 12.01; break;
case 'H' : count += 1.008; break;
case 'O' : count += 16.00; break;
case 'N' : count += 14.01; break;
}
}
}
}
cout << fixed << setprecision() << count << endl;
}
return ;
}
chaper3_exerise_Uva1568_Molar_Mass_分子量的更多相关文章
- 分子量 (Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)
解题思路: 1.将分子量用double 数组记录下来 2.将字符串存储在字符数组中,从头向后扫描,一直记住“字母”,对下一个字符进行判断,是否是数字,如果是数字:用一个整数记录,本代码中用的sum,同 ...
- 分子量 (Molar Mass,ACM/ICPC Seoul 2005,UVa1586)
习题 3-3 分子量 (Molar Mass,ACM/ICPC Seoul 2005,UVa1586) 给出一种物质的分子式(不带括号),求分子量.本题中的分子式只包含4种原子,分别为C,H,O,N, ...
- 课后题--------求分子量-----Molar mass------
简单的化学式 求分子量问题 下面附上 代码和解析. #include<stdio.h> #include<algorithm> #include<string.h&g ...
- 分子量(JAVA语言)
package 第三章习题; /* * 给出一种物质的分子式(不带括号)求分子量. * 本题分子只包含4种原子,分别为C,H,O,N * 分子量为分别为12.01,1.008,16.00,14 ...
- 【OI】计算分子量 Molar mass UVa 1586 题解
题目:(由于UVa注册不了,还是用vjudge) https://vjudge.net/problem/UVA-1586 详细说明放在了注释里面.原创. 破题点在于对于一个元素的组合(元素+个数),只 ...
- 【C/C++】习题3-2 分子量/算法竞赛入门经典/字符串
给出一种物质的分子式,求分子量.只包含4种原子,分别为C,H,O,N. [知识点] 1.ASCII码 [阿拉伯数字]48~57 [大写字母]65~90 [小写字母]97~122 2.输入循环到n-1的 ...
- 分子量(Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)
#include<stdio.h>#include<stdlib.h>#include<string.h>int main(){ char s[20]; scanf ...
- 分子量(UVa1586)
题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=830&a ...
- 习题3-2 分子量(Molar Mass, ACM/ICPC Seoul 2007, UVa1586)
#include<stdio.h> #include<string.h> #include<ctype.h> double getweight(char x) { ...
随机推荐
- WPF:自定义路由事件的实现
路由事件通过EventManager,RegisterRoutedEvent方法注册,通过AddHandler和RemoveHandler来关联和解除关联的事件处理函数:通过RaiseEvent方法来 ...
- Ubuntu 下apache2开启rewrite隐藏index.php
为了实现 http://www.example.com/route/route 而不是 http://www.example.com/index.php/route/route 需要开启apache2 ...
- 利用LruCache为GridView异步加载大量网络图片完整示例
MainActivity如下: package cc.testlrucache; import android.os.Bundle; import android.widget.GridView; i ...
- http://five-js.envylabs.com/
一个很有意思的播报javascript最新资讯的网站http://five-js.envylabs.com/
- ruby on rails validates uniqueness
最近在处理一个小功能,每个元素可以有多个图片,每个图片的name表示了它是背景图还是海报图, 需要对每个元素的图片name做一个唯一性验证,一个元素不能添加两个海报图, 需要使用的是validates ...
- hibernate 学习知识总结
1.最近用hibernate 学会很多知识,总结如下: (1)数据库表格已经设置默认值,在进行数据插入的时候,bean里面不赋值的话,插入之后该字段依旧是null 是因为hibernate默认插入和更 ...
- am335x sd卡启动开启识别emmc kernel 上的改动
sbc 7109-454 sd 卡启动qt系统后一直识别不了 emmc 也就是mmc1口, 一开始以为是硬件初始化的问题,后面又以为是io口复用,最后才知道是根本没有注册mmc1设备. 更改下面的代 ...
- 阻止a标签默认跳转事件
1:<a href="####"></a> 2:<a href="javascript:void(0)"></a> ...
- django的cookie 和session
Cookie 1.获取cookie: request.COOKIES['key'] request.get_signed_cookie(key, default=RAISE_ERROR, salt=' ...
- git分支管理策略
http://www.ruanyifeng.com/blog/2012/07/git.html https://www.digitalocean.com/community/tutorials/how ...