hdu 3787 A+B(简单字符串处理)
2016-03-20 22:19
375 查看
Problem Description
给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。 现在请计算A+B的结果,并以正常形式输出。
Input
输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。
Output
请计算A+B的结果,并以正常形式输出,每组数据占一行。
Sample Input
-234,567,890 123,456,789 1,234 2,345,678
Sample Output
-111111101 2346912
Source
浙大计算机研究生复试上机考试-2010年
水题,简单字符串处理
#include<iostream> #include<string> #define MAX_N 20; using namespace std; long long get(string s){ int mark=1; long long dig=0; int i=0; if(s[0]=='-'){ mark=-1; i++; } for(i;i<s.size();i++){ if(s[i]!=',') dig=dig*10+s[i]-'0'; } return dig*mark; } int main(){ string s1,s2; while(cin>>s1>>s2){ cout<<get(s1)+get(s2)<<endl; } }
相关文章推荐
- 波兰数 总结
- 问题 A: 求素数
- 猎豹MFC--框架结构剖析--不用向导--单文档视图 非对话框
- Hibernate逍遥游记-第13章 映射实体关联关系-005双向多对多(使用组件类集合\<composite-element>\)
- 第3周项目6-小学生计算器
- 第四周项目五-用递归方法求解(求n的阶乘)
- Unable to execute dex: Multiple dex files define Landroid/support/v4/accessibilityservice/Accessibil
- Java框架:strurs(1)
- Hibernate高级查询方法
- Scala--样例类(case)详解
- nginx apache
- 作为一个女孩,我们努力的意义~
- 【python】:python中time和calendar模块重要函数详解
- 找对象法门-解放天性训练
- R语言中的模型修正函数update
- Python 从零学起——读《笨办法学Python v1.0》小结 随时更新
- JS仿百度搜索自动提示框匹配查询功能
- vs2013单元测试练习过程
- 复利计算4.0
- springMVC+ajax分页查询