Saturday, April 28, 2012

Adding Reversed Numbers

( https://www.spoj.pl/problems/ADDREV/ )
//#include <cstdio> // to compile as C++
#include <stdio.h>

int rev(int num) {
    int res = 0;
    while(num > 0) {
        res = res*10 + num%10;
        num /= 10;
    }
    return res;
}

int main() {
    int cases, x, y;
    scanf("%d", &cases);
    while(cases--) {
        scanf("%d %d", &x, &y);
        printf("%d\n", rev(rev(x)+rev(y)));
    }
    return 0;
}

No comments:

Post a Comment