[Molar Mass, ACM/ICPC Seoul 2007, UVA1586]
来源:互联网 发布:linux文件内容复制 编辑:程序博客网 时间:2024/05/01 13:02
[Molar Mass, ACM/ICPC Seoul 2007, UVA1586]
主要是固定位 的思想,这是最后的代码,不过中间一直wrong answer,一直找不出,原来是15写成了14.
#include <stdio.h>#include <string.h>int isnum(char c) { return c>='0' && c<='9';}int main() { int T; char s[85]; //freopen("test.txt", "r", stdin); double wei[15]; wei['C'- 'A'] = 12.01; wei['H'- 'A'] = 1.008; wei['O'- 'A'] = 16.00; wei['N'- 'A'] = 14.01; scanf("%d", &T); while(T--) { scanf("%s", s); int len = strlen(s); double sum = 0; for(int i=0; s[i]!='\0'; ++i) { if(i+3 == len) { if(isnum(s[i+1]) && isnum(s[i+2])) { sum += wei[s[i] - 'A'] * ((s[i+1] - '0')*10 + (s[i+2] - '0')); break; } else if(isnum(s[i+1])) { sum += wei[s[i] - 'A']; i++; } } if(i+2 == len && isnum(s[i+1])) { sum += wei[s[i] - 'A'] * (s[i+1] - '0'); break; } if(isnum(s[i+1]) && isnum(s[i+2])) { sum += wei[s[i] - 'A'] * ((s[i+1] - '0')*10 + (s[i+2] - '0')); i+=2; } else if(isnum(s[i+1])) { sum += wei[s[i] - 'A'] * (s[i+1] - '0'); i++; } else { sum += wei[s[i] - 'A']; } } printf("%.3f\n", sum); } return 0;}
阅读全文
0 0
- [Molar Mass, ACM/ICPC Seoul 2007, UVA1586]
- 分子量(Molar Mass, ACM/ICPC Seoul 2007, UVa1586)
- 分子量(Molar Mass,ACM/ICPC Seoul 2007,UVa1586)
- 分子量 (Molar Mass, ACM/ICPC Seoul 2007, UVa1586)
- 习题3-2 分子量(Molar Mass, ACM/ICPC Seoul 2007, UVa1586)
- 算法竞赛入门经典-习题3-2 分子量(Molar Mass, ACM/ICPC Seoul 2007, UVa1586)
- Molar Mass, ACM/ICPC Seoul 2007,Uva1586 给出一种物质的分子式,求分子量
- 分子量(Molar Counting, ACM/ICPC Seoul 2007, UVa1586)
- Molar Mass, ACM/ICPC Seoul 2007, UVa 1586
- 分子量(Molar Counting, ACM/ICPC Seoul 2007)
- 3900 - Molar mass Asia - Seoul - 2007/2008
- uva1586----Molar mass
- UVA1586 - Molar mass
- Uva1586 - Molar mass
- UVA1586 Molar mass
- uva1586 - Molar mass
- 分子量 Molar Mass uva1586
- UVa1586 Molar Mass
- Windows7以上使用WFP驱动框架实现IP数据包截取(一)
- 【Openjudge】出栈序列统计
- 阅读文章:Incorporating Knowledge Graph Embeddings into Topic Modeling
- shiro自定义realm无法使用注解
- Educational Codeforces Round 30 Balanced Substring 前缀和
- [Molar Mass, ACM/ICPC Seoul 2007, UVA1586]
- 矩阵乘法(Strassen 算法实现)
- 设计全局ER模型 数据库系统原理(2007版) 课程代码4735 笔记
- UVa 1471 Defense Line 防线
- 二叉树-中序遍历
- Spring框架的注释问题
- Java基础之逐步击破----九九乘法表
- 网站图片应如何SEO优化?
- SpringMVC单文件文件上传