ACM coder [T1002] has been wrong answer, do not know why. On the code! Right, right!

Source: Internet
Author: User

#include <stdio.h>#include<stdbool.h>#defineArraylength 20#defineBitmax 1000Main () {CharInputa[arraylength][bitmax]; CharInputb[arraylength][bitmax]; CharResult[arraylength][bitmax +1]; intCasecount =0; scanf_s ("%d", &casecount);  for(inti =0; i < Casecount; i++) {scanf_s ("%s", &inputa[i][0], +); scanf_s ("%s", &inputb[i][0], +); }    //calculating ... result[0],result[1]     for(intCasenum =0; Casenum < Casecount; casenum++)    {        Char*ptra, *PTRB, *Ptrresult; PtrA=Inputa[casenum]; PTRB=Inputb[casenum]; Ptrresult=Result[casenum]; intLengtha =Getlengh (PtrA); intLENGTHB =Getlengh (PTRB); intLengthmax = LENGTHA&GT;LENGTHB?LENGTHA:LENGTHB; //Fill A or B with zero        if(Lengtha >LENGTHB) {PTRB+=LENGTHB;  for(intj =0; J <= LENGTHB; J + +)            {                Chartemp = *PTRB; * (PTRB + LENGTHA-LENGTHB) =temp; PTRB--; } PTRB=Inputb[casenum];  for(inti =0; i < LENGTHA-LENGTHB; i++){                *PTRB ='0'; PTRB++; }        }        Else{PtrA+=Lengtha;  for(intj =0; J <= Lengtha; J + +)            {                Chartemp = *PtrA; * (PtrA + Lengthb-lengtha) =temp; PtrA--; } PtrA=Inputa[casenum];  for(inti =0; i < Lengthb-lengtha; i++){                *ptra ='0'; PtrA++; }        }         for(inti =0; I <= Lengthmax; i++){            *ptrresult ='0'; Ptrresult++; }        *ptrresult =' /'; BOOLGoahead =false; PtrA= &inputa[casenum][lengthmax-1]; PTRB= &inputb[casenum][lengthmax-1]; Ptrresult--; //Calculate Result[i]         for(inti =0; i < Lengthmax; i++)        {            intBita = *ptra-'0'; intBITB = *PTRB-'0'; *ptrresult ='0'+ (Bita + BITB + goahead)%Ten; if(Bita + BITB + goahead >=Ten) {Goahead=true; }            Else{Goahead=false; } PtrA--; PTRB--; Ptrresult--; }        if(Goahead = =true){            *ptrresult ='1'; }        Else{Ptrresult++; } PtrA++; PTRB++;  for(intBitnum =0; Bitnum < Lengtha; bitnum++){            if(*ptra = ='0') PtrA++; Else            {                 Break; }        }         for(intBitnum =0; Bitnum < LENGTHB; bitnum++){            if(*PTRB = ='0') PTRB++; Else            {                 Break; }} printf ("Case %d:\n%s +%s =%s\n\n", Casenum +1, PtrA, PTRB, Ptrresult); }}//Get string lengthintGetlengh (Char*ptr) {    intLength =0;  while(*ptr! =' /') {ptr++; Length++; }    returnlength;}

Problem Descriptioni has a very simple problem for you. Given-integers A and B, your job is-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 be exceed 1000.OutputFor each test case and 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 Input
21 2112233445566778899 998877665544332211
Sample Output
Case 1:1 + 2 = 3Case 2:1.,122,334,455,667,79e,+17 + 998877665544332211 = 1111111111111111110

ACM coder [T1002] has been wrong answer, and I don't know why. On the code! Right, right!

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.