C++高分求助!A + B Problem II

来源:百度知道 编辑:UC知道 时间:2024/06/23 14:54:10
在杭电上做的1002,大数相加A+B问题2;提交时很多次都是提示我答案错误;高手来看看哪里错了~~指出一下,thank u!

题目:
Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.

Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.

Sample Input
2
1 2
112233445566778899 998877665544332211

为什么是败笔啊,其实真正用C写的基本上没有了,再说现在编译器谁还守着C一种语言啊

cout是的A

输入20次可以这样来解决:
int i=0;
while(cin>>x)
{
……
……
i++;
}
该问题没有什么很高深的算法凡是一个高精度数相加问题,对于高精度数可以通过数组来处理。至于具体的实现,我想你自己也可以写出来了。

acm int main(){return 0;}用void会错的

#include<iostream>
using namespace std;

void main()
{
char in1[1000],in2[1000];
int line;
cin >> line;
int i = 1;
while(i<=line)
{
cin>>in1;
cin.get();
cin>>in2;
cout << "Case "<<i<<":\n";
cout <<in1<<" + "<<in2<<" = ";

int len1 = strlen(in1);
int len2 = strlen(in2);

int cc = 0;
int k = 0;
char *p;
if(len1 > len2) p = new char[len1+1];
else p =