ACM_UVA1586
来源:互联网 发布:矩阵的平方 编辑:程序博客网 时间:2024/05/18 13:47
</pre><p><span style="background-color: rgb(240, 240, 240);">#include<iostream></span></p><p><pre name="code" class="cpp">using namespace std;#include<string.h>int main(){char s[30];scanf("%s", s);double sum = 0.0;double w;int len = strlen(s);//printf("%d", '6' - '0');for (int i = 0; i < len; ){switch (s[i]){case'C': w = 12.01;break;case'H': w = 1.008;break;case'O': w = 16.00;break;case'N': w = 14.01;break;}if (i + 1 < len && s[i + 1] <= '9'){int tail = i + 1;while (tail < len && (s[tail] <= '9'))tail++;int v = tail - 1;int n = 0;int y = 1;while (v != i){n += ((s[v] - '0') * y);y *= 10;v--;}sum += (w * n);i = tail;}else{sum += w;i++;}}printf("%.3f", sum);}
总结:
1.当要使用i+1时,边界处要对其经常判定
2.注意变量的作用域。
0 0
- ACM_UVA1586
- POJ-3579
- java一些面试题
- MIT-BIH ECG 心电数据的下载和读取图解
- 二叉树知道前序中序或者中序后序求另外一个排列
- Cocos2d-x学习笔记(二)-------->CCDirector导演类
- ACM_UVA1586
- Untrusted Patrol
- Windows8 上面安装Oracle 11g 时,安装程序报错:[INS-13001]环境不满足最低要求
- 图片剪裁
- linux磁盘占用100%的解决方法
- main(int argc,char* argv[],char *envp[] )
- 详解Oracle DELETE和TRUNCATE 的区别
- 中秋快乐&&股市飘红--- Best Time to Buy and Sell Stock III&& II&&I
- hdu1026——Ignatius and the Princess I