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],tb[1002];
13     getchar();
14     while(T--)
15     {
16         K++;
17         scanf("%s%s",a,b);
18         memset(ta,0,sizeof(ta));
19         memset(tb,0,sizeof(tb));
20         int l,l1,l2;
21         l1=strlen(a);
22         l2=strlen(b);
23         if(l1<=l2)
24             l=l2;
25         else l=l1;
26         for(int i=0;i<l;i++)
27         {
28             if(l1-1>=0)
29             {
30                 ta[i]=a[l1-1]-‘0‘;
31             }
32             else ta[i]=0;
33             l1--;
34             if(l2-1>=0)
35             {
36                 tb[i]=b[l2-1]-‘0‘;
37             }
38             else tb[i]=0;
39             l2--;
40         }
41         int t;
42         for(int i=0;i<l;i++)
43         {
44             t=ta[i]+tb[i];
45             if(t>=10)
46             {
47                 ta[i]=t-10;
48                 ta[i+1]++;
49             }
50             else ta[i]=t;
51         }
52         printf("Case %d:\n",K);
53         printf("%s + %s = ",a,b);
54         int flag=0;
55         for(int i=l;i>=0;i--)
56         {
57             if(flag||ta[i])
58             {
59                 flag=1;
60                 printf("%d",ta[i]);
61             }
62         }
63         if(flag==0)
64             printf("0");
65
66         printf("\n");
67             if(K!=T)
68             printf("\n");
69     }
70     return 0;
71 }

A + B Problem II(大数加法),布布扣,bubuko.com

时间: 2024-09-12 05:19:17

A + B Problem II(大数加法)的相关文章

(hdu step 2.3.1)A + B Problem II(大数加法)

题目: A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2372 Accepted Submission(s): 917   Problem Description I have a very simple problem for you. Given two integers A and B, your j

hdu1002 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): 230247    Accepted Submission(s): 44185 Problem Description I have a very sim

HDU1002 -A + B Problem II(大数a+b)

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 315214    Accepted Submission(s): 61139 Problem Description I have a very simple problem for you. Given two integers A and B, you

HDU1002 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): 409136    Accepted Submission(s): 79277 Problem Description I have a very si

HDU 1023 Train Problem II 大数打表Catalan数

一个出栈有多少种顺序的问题.一般都知道是Catalan数了. 问题是这个Catalan数非常大,故此须要使用高精度计算. 并且打表会速度快非常多.打表公式要熟记: Catalan数公式 Cn=C(2n,n) / (n+1); 递推公式 C(n ) = C(n-1)*(4*n-2) / (n+1) 高精度乘以一个整数和高精度除以一个整数的知识.这样还是使用整数数组比較好计算,假设使用string那么就不太好计算了,由于整数也可能是多位的. const int MAX_N = 101; short

抓起根本(二)(hdu 4554 叛逆的小明 hdu 1002 A + B Problem II,数字的转化(反转),大数的加法......)

数字的反转: 就是将数字倒着存下来而已.(*^__^*) 嘻嘻…… 大致思路:将数字一位一位取出来,存在一个数组里面,然后再将其变成数字,输出. 详见代码. 1 while (a) //将每位数字取出来,取完为止 2 { 3 num1[i]=a%10; //将每一个各位取出存在数组里面,实现了将数字反转 4 i++; //数组的变化 5 a/=10; 6 } 趁热打铁 例题:hdu 4554 叛逆的小明 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid

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

hdoj 1002 A + B Problem II【大数加法】

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 260585    Accepted Submission(s): 50389 Problem Description I have a very simple problem for you. Given two integers A and B, you