A + B (9 degree oj question 60)

Source: Internet
Author: User

Preface I caught a cold this weekend and never wrote a program. I got a question and practiced it. It is strange that this question can only be used as a global array. Passing parameters will always cause problems and gdb has not been debugged, this is too strange. Question [html] Description: implement a calculator to output the value of a + B. Input: the input includes two numbers a and B. The number of digits a and B cannot exceed 1000. Output: multiple groups of test data may exist. For each group of data, the value of a + B is output. Sample input: 2 6 10000000000000000000 10000000000000000000000000000000 sample output: 8 10000000000010000000000000000000 ac code [cpp] # include <stdio. h> # include <stdlib. h> # include <string. h> # define MAX 1002 char a [MAX], B [MAX], sum [MAX]; void bigDataPlus (); int main () {while (scanf ("% s", a, B )! = EOF) {bigDataPlus (); printf ("% s \ n", sum);} return 0;} void bigDataPlus () {int I, j, k, c, len_a, len_ B; // initialize memset (sum, 0, sizeof (sum); len_a = strlen (a); len_ B = strlen (B ); // carry ID c = 0; for (I = len_a-1, j = len_ B-1, k = 0; I> = 0 & j> = 0; I --, j --, k ++) {sum [k] = a [I] + B [j] + c-'0'; if (sum [k]> '9 ') {c = 1; sum [k]-= 10;} else {c = 0 ;}// a> B while (I> = 0) {sum [k] = a [I] + c; if (sum [k]> '9') {sum [k]-= 10; c = 1 ;} else {c = 0;} k ++; I --;} // B> a while (j> = 0) {sum [k] = B [j] + c; if (sum [k]> '9') {sum [k]-= 10; c = 1;} else {c = 0;} k ++; j --;} // if (c = 1) {sum [k ++] = '1';} // flip char temp; for (I = 0, j = k-1; I <j; I ++, j --) {temp = sum [I]; sum [I] = sum [j]; sum [j] = temp ;}} /*************************************** * *********************** Problem: 1198 User: wangzhengyi Language: C Result: Accepted Time: 30 MS Memory: 912 kb ************************************** **************************/

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.