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