UVA713 UVALive5539 POJ1504 ZOJ2001 Adding reversed Numbers

Source: Internet
Author: User

Regionals 1998 >> Europe-central

Problem Link: UVA713 UVALive5539 POJ1504 ZOJ2001 Adding reversed Numbers. Introductory exercises, written in C language.

Test instructions: Enter two integers, all reversed (reverse order) and then summed, the output is added and reversed (reverse).

Problem analysis: Integers can be large, up to 200 bits, and the left 0 need to be removed after the add result is reversed.

The program encapsulates two functions to make the logic simpler and clearer.

The C language Program of AC is as follows:

/* UVA713 UVALive5539 POJ1504 ZOJ2001 Adding Reversed Numbers * * #include <stdio.h> #include <string.h> #define    MAXN 200void revers (char s[]) {int start, end;    start = 0;    End = Strlen (s)-1;        while (Start < end) {char temp;        temp = S[start];        S[start] = S[end];        S[end] = temp;        start++;    end--;    }}int Add (char s[], Char t[], char r[]) {int I, j, K, C;    i = strlen (s)-1;    j = strlen (t)-1;    c = 0;    k = 0; while (i >= 0 | | J >= 0) {if (i >= 0) r[k] = s[i]-' 0 ' + ((j>=0)? (        T[J]-' 0 '): 0) + C;        else r[k] = t[j]-' 0 ' + C;            if (R[k] >=) {r[k] = R[k]-10 + ' 0 ';        c = 1;            } else {r[k] = r[k] + ' 0 ';        c = 0;        } i--;        j--;    k++;    } if (C > 0) r[k++] = c + ' 0 ';    R[k] = ' + ';    i = 0;    while (I < k && R[i] = = ' 0 ') i++; return i;} int main (void) {int n, start; Char s[maxn+1], t[maxn+1], Ans[maxn+<span style= "Font-family:simsun;"    >2</span>];    scanf ("%d", &n);        while (n--) {scanf ("%s%s", S, t);        Revers (s);        Revers (t);        Start = Add (S, t, ans);    printf ("%s\n", ans + start); } return 0;}


UVA713 UVALive5539 POJ1504 ZOJ2001 Adding reversed Numbers

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.