codeup 1817 A+B
来源:互联网 发布:淘宝图标图片 编辑:程序博客网 时间:2024/06/05 03:45
codeup 1817 A+B
题目描述
给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号”,”隔开。
现在请计算A+B的结果,并以正常形式输出。
输入
输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。
输出
请计算A+B的结果,并以正常形式输出,每组数据占一行。
解题代码
#include <iostream>#include <string>using namespace std;int main(){ string str1,str2; while(cin>>str1>>str2) { int len1 = str1.length(); int len2 = str2.length(); int a,b; a=b=0; //之前忘记初始化 if(str1[0]=='-') { for(int j=1;j<len1;j++) { if(str1[j]==',') continue; a = a*10 + str1[j]-'0'; } a *= -1; } else { for(int j=0;j<len1;j++) { if(str1[j]==',') continue; a = a*10 + str1[j]-'0'; } } if(str2[0]=='-') { for(int j=1;j<len2;j++) { if(str2[j]==',') continue; b = b*10 + str2[j]-'0'; } b *= -1; } else { for(int j=0;j<len2;j++) { if(str2[j]==',') continue; b = b*10 + str2[j]-'0'; } } int ans = a+b; cout<<ans<<endl; } return 0; }
阅读全文
0 0
- codeup 1817 A+B
- codeup
- CodeUp-1036 Problem B镂空三角形
- codeup--2345
- codeup刷题
- codeup 1126
- a>b?a:b
- a+b
- a+++b
- A + B
- A+B
- A+B
- {A} + {B}
- a+++b
- A+B
- A-B
- A+B
- A + B
- JAVA 并发编程学习总结
- 2-4端口\富规则firewall
- css重点
- Tunnel Warfare HDU
- 生产者与消费者模型
- codeup 1817 A+B
- 浅拷贝和深拷贝
- HTTP相关知识
- 前端工程化初识
- 禁用和启用windows defender
- 一个简单的放大镜
- MQL4 语言入门。简单词组中的难题。
- 2017.07.24-0811 没写日记
- linux学习之旅(十八)&深入DNS服务器