1198_a+b
来源:互联网 发布:北京地铁软件 编辑:程序博客网 时间:2024/06/03 16:38
// 1198_a+b.cpp : 定义控制台应用程序的入口点。//题目1198:a+b//时间限制:1 秒内存限制:32 兆特殊判题:否提交:8598解决:2968//题目描述://实现一个加法器,使其能够输出a+b的值。//输入://输入包括两个数a和b,其中a和b的位数不超过1000位。//输出://可能有多组测试数据,对于每组数据,//输出a+b的值。//样例输入://2 6//10000000000000000000 10000000000000000000000000000000//样例输出://8//10000000000010000000000000000000//来源://2010年华中科技大学计算机研究生机试真题#include "stdafx.h"#include "stdio.h"#include "iostream"#include "string"#include "algorithm"using namespace std;int main(){ string a,b; char c[1010]; while(cin>>a>>b){ reverse(a.begin(),a.end()); reverse(b.begin(),b.end()); int cn,i,j; cn = i = 0; while(i<a.length() && i<b.length()){ c[i] = (a[i]-'0' + b[i]- '0' + cn)%10 + '0'; cn = (a[i]-'0' + b[i] -'0'+ cn)/10; i++; } while(i<a.length()){ c[i] = (a[i]-'0' + cn)%10 + '0'; cn = (a[i]-'0' + cn)/10; i++; } while(i<b.length()){ c[i] = (b[i]-'0' + cn)%10 + '0'; cn = (b[i] -'0'+ cn)/10; i++; } if(cn==1){ c[i] = 1+ '0'; c[i+1] = '\0'; reverse(c,c+i+1); } else{ c[i] = '\0'; reverse(c,c+i); } cout<<c<<endl; } return 0;}/*reverse();*/
0 0
- 1198_a+b
- 1003_A+B
- Problem - 1000_A + B Problem
- 1017_A除以B (20)
- 1001_A+B for Matrices
- 入门训练4_A+B问题
- Problem - 1002_A + B Problem II
- 1011_A+B和C (15)
- 南邮 OJ 2096 1_A+B(I)
- 南邮 OJ 2097 2_A+B(II)
- 南邮 OJ 2098 3_A+B(III)
- NOJ2098 3_A+B(III)(大数加法)
- pat考试准备_A+B for Polynomials
- 【OpenJudge】c语言_A*B问题
- ACM之北大——1000_A+B Problem
- ACM之杭电——1000_A + B Problem
- 杭电OJ-2054_A == B ?
- USB2.0_A型、B型、Mini和Micro接口
- 欢迎使用CSDN-markdown编辑器
- 93. Restore IP Addresses
- 开发中常用网站
- Tensorflow PlayGround初体验
- 如何写好递归算法
- 1198_a+b
- 前端工程师开发进阶之路
- Android 6.0 数据绑定之DataBinding(一)
- 阿里巴巴 JAVA 开发手册-编程规约-常量定义
- Image retrieval C++ implementation
- 94. Binary Tree Inorder Traversal
- 内存气球技术实验(Memory Balloon)
- android学习笔记(9)-push to git
- 95. Unique Binary Search Trees II