Hdoj 1002 A + B problem II

Source: Internet
Author: User

A + B Problem II

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 242959 Accepted Submission (s): 46863


Problem Descriptioni has a very simple problem for you. Given integers A and B, your job is to calculate the Sum of A + B.

Inputthe 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 both positive integers, A and B. Notice that the integers is very large, that M EANs should not process them by using 32-bit integer. Assume the length of each integer would not exceed 1000.

Outputfor Each test case, you should output of the lines. The first line was "Case #:", # means the number of the the test case. The second line is the equation "A + b = sum", sum means the result of A + B. Note there is some spaces int the Equati On. Output a blank line between the test cases.

Sample Input21 2112233445566778899 998877665544332211Sample outputcase 1:1 + 2 = 3

Case 2:1.,122,334,455,667,79e,+17 + 998877665544332211 = 1111111111111111110

Pay attention to zeroing the array

#include <stdio.h> #include <stdlib.h> #include <string.h> int main () {    int m,j,n,i,l1,l2,t,k=1;    Char s1[1100];    Char s2[1100];    int s3[1100];    int s4[1100];scanf ("%d", &n), while (n--) {scanf ("%s%s", s1,s2); memset (s3,0,sizeof (  S3)); Clear the array 0 memset (s4,0,sizeof (S4)); L1=strlen (S1); L2=strlen (S2) t=0;for (j=l1-1,i=0;j>=0;j--, i++) s3[i]=s1[j]-' 0 ';                  Converts a string to a number for (j=l2-1,i=0;j>=0;i++,j--) s4[i]=s2[j]-' 0 ', for (i=0;i<1100;i++) {s3[i]+=s4[i];if (s3[i]>=10)                //Sum to you {s3[i]-=10;s3[i+1]++;}} printf ("Case%d:\n", k++);p rintf ("%s +%s =", s1,s2), and for (i=1099;i>=0;i--) if (s3[i]!=0) break;for (; i>=0;i--) printf ("%d", S3[i]);p rintf ("\ n"), if (n>0) printf ("\ n");} return 0;}

  

Hdoj 1002 A + B problem II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.