#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char s[20];
scanf("%s", s); double sum = 0;
for (int i = 0; i < strlen(s); i++) {
if (s[i] == 'C') sum += (s[i + 1] - 48) * 12.01;
if (s[i] == 'H')
{
if (s[i + 1] >= '0'&&s[i + 1] <= '9')
sum += (s[i + 1] - 48) *1.008;
else
sum += 1.008;
}
if (s[i] == 'O')
{
if (s[i + 1] >= '0'&&s[i + 1] <= '9')
sum += (s[i + 1] - 48) * 16.00;
else
sum += 16.00;
}

}
printf("%.3f", sum);
system("pause");
}

分子量(Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)的更多相关文章

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

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

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

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

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

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

  4. 数数字 (Digit Counting,ACM/ICPC Danang 2007,UVa 1225)

    思路: 利用java 特性,将数字从1 一直加到n,全部放到String中,然后依次对strring扫描每一位,使其carr[str.charAt(i)-'0']++; 最后输出carr[i],即可. ...

  5. 得分(Score,ACM/ICPC Seoul 2005,UVa 1585)

    #include<stdio.h> int main(void) { char b; int t,cou,sum; scanf("%d",&t); getcha ...

  6. 生成元(Digit Generator ,ACM/ICPC Seoul 2005 ,UVa 1583)

    生成元:如果 x 加上 x 各个数字之和得到y,则说x是y的生成元. n(1<=n<=100000),求最小生成元,无解输出0. 例如:n=216 , 解是:198 198+1+9+8=2 ...

  7. 得分(Score, ACM/ICPC Seoul 2005,UVa 1585)

    #include<cstdio>#include<cstdlib>#include<cstring>int main(){ char s[80];//输入OOXXO ...

  8. 生成元(Digit Generator,ACM/ICPC Seoul 2005,UVa 1583)

    #include<cstdio>#include<cstdlib>#include<cstring>using namespace std;int t, n, a, ...

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

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

随机推荐

  1. Java笔记:String类

    1.String类是不可变类,一旦一个String对象被创建以后,包含在这个对象中的字符序列式不可改变的,直至这个对象被销毁. String s1 = "java"; s1 = s ...

  2. SVM学习资料

    SVM学习资料 2013-06-21 17:29 by 夜与周公, 227 阅读, 0 评论, 收藏, 编辑 SVM(support vector machine),被认为是“off-the-shel ...

  3. 设计模式之 - 外观模式 (Facade design pattern)

    1. 模式意图:  为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这一子系统更容易使用. 2. 结构 3. 工厂方法模式C#实现 using System; ...

  4. Debian下的'aptitude update'失败处理

    Hit http://ftp.us.debian.org squeeze/contrib amd64 Packages Hit http://download.proxmox.com squeeze/ ...

  5. Android与js交互实例

    Android 中可以通过webview来实现和js的交互,在程序中调用js代码,只需要将webview控件的支持js的属性设置为true Android(Java)与JavaScript(HTML) ...

  6. java如何避免死锁

    在有些情况下死锁是可以避免的.本文将展示三种用于避免死锁的技术: 加锁顺序 加锁时限 死锁检测 加锁顺序 当多个线程需要相同的一些锁,但是按照不同的顺序加锁,死锁就很容易发生. 如果能确保所有的线程都 ...

  7. bzoj 1430: 小猴打架 -- prufer编码

    1430: 小猴打架 Time Limit: 5 Sec  Memory Limit: 162 MB Description 一开始森林里面有N只互不相识的小猴子,它们经常打架,但打架的双方都必须不是 ...

  8. SpringAOP导致@Autowired依赖注入失败

    之前用springAOP做了个操作日志记录,这次在往其他类上使用的时候,service一直注入失败,找了网上好多内容,发现大家都有类似的情况出现,但是又和自己的情况不太符合.后来总结自己的情况发现:方 ...

  9. IONIC之简易购物车

    HTML <div ng-app="app"> <div class="l-header"> <div class="l ...

  10. iOS开发-OC语言 (六)点语法和@property

    点语法和@property 知识点 1.setter/getter函数 2.点语法 3.@property语法和属性 ======================================== ...