sdut2613(This is an A+B Problem)大数加法

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
char a[1010],b[1010];
int ta[1010],tb[1010];
int main()
{
int l2,l1,l;
while(scanf("%s%s",a,b)!=EOF)
{
memset(ta,0,sizeof(ta));
memset(tb,0,sizeof(tb));
l1=strlen(a);
l2=strlen(b);
if(l1<l2) l=l2;
else l=l1;
for(int i=0;i<l;i++)
{
if(l1-1>=0)
{
ta[i]=a[l1-1]-‘0‘;
l1--;
}
else ta[i]=0;
if(l2-1>=0)
{
tb[i]=b[l2-1]-‘0‘;
l2--;
}
else tb[i]=0;
}
int t;
for(int i=0;i<l;i++)
{
t=ta[i]+tb[i];
if(t>=10)
{
ta[i]=t-10;
ta[i+1]++;
}
else ta[i]=t;
}
int flag=0;
for(int i=l;i>=0;i--)
{
if(flag||ta[i])
{
flag=1;
printf("%d",ta[i]);
}
}
if(!flag) printf("0");//用于解决只有0相加的状况
printf("\n");

}
return 0;
}

sdut2613(This is an A+B Problem)大数加法

时间: 2024-08-10 21:06:18

sdut2613(This is an A+B Problem)大数加法的相关文章

A + B Problem II(大数加法)

一直格式错误,不想改了,没A 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <stdlib.h> 5 using namespace std; 6 7 int main() 8 { 9 int T,K=0; 10 scanf("%d",&T); 11 char a[1002],b[1002]; 12 int ta[1002],

A + B Problem II(大数加法)

http://acm.hdu.edu.cn/showproblem.php?pid=1002 A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 261608    Accepted Submission(s): 50625 Problem Description I have a very simple p

题解报告:hdu 1002 A + B Problem II(大数加法)

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 fol

POJ 1053 Integer Inquiry (大数加法,还是Java大法好)

Integer Inquiry Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 32674   Accepted: 12789 Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he

Hat&#39;s Fibonacci(大数加法+直接暴力)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 hdu1250: Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9442    Accepted Submission(s): 3096 Problem Description A Fibonacci

hdu_1041(Computer Transformation) 大数加法模板+找规律

Computer Transformation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8367    Accepted Submission(s): 3139 Problem Description A sequence consisting of one digit, the number 1 is initially wri

POJ 1053 Integer Inquiry &amp;&amp; HDOJ 1047 Integer Inquiry (大数加法)

题目链接(POJ):http://poj.org/problem?id=1503 题目链接(HDOJ):http://acm.hdu.edu.cn/showproblem.php?pid=1047 Integer Inquiry Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30856   Accepted: 12007 Description One of the first users of BIT's new su

HDU 1250 大数加法

Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6948    Accepted Submission(s): 2285 Problem Description A Fibonacci sequence is calculated by adding the previous two members the

HDU 1250 Hat&#39;s Fibonacci (递推、大数加法、string)

Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 14776    Accepted Submission(s): 4923   Problem Description A Fibonacci sequence is calculated by adding the previous two members