每天更新一道OJ题目,今日介绍简单整数和大数加法的使用方法和示例。
前言
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
这里使用多种解法来对其进行编译。
一、输入
示例: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.
二、输出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.
代码
1、示例: #include#include int main() { long a,b,sum; scanf("%ld%ldn",&a,&b); sum = a + b; printf("%ldn",sum); return 0; } 2、示例:超长(超100位)加法运算 #include #include #define N 10000 int main() { char num1[N] = {0},num2[N] = {0},result[N]={0}; long len_1,len_2,len; int i; scanf("%s %s",num1,num2); len_1 = strlen(num1); len_2 = strlen(num2); len = (len_1>len_2) ? len_1:len_2; len++; for(i = 0 ;i len_2) { for(;i 0;i--) { if(result[i]>=10) { result[i] = result[i]%10; result[i-1]++; } } //判断是后位数多出一位 9+8=17变成2位数,如果没有则全部前移。并变回数字的ASC2码 if(result[0]!= 0) { for(i = 0;i


