SPOJ Adding Reversed Numbers
#include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #define sf scanf #define pf printf using namespace std; typedef unsigned long long ull; typedef long L; ull reverse_num(ull n) { ull a=n,add=0,b=n; while(a>0) { a%=10; add = a+(add*10); b/=10; a=b; } return add; } int main() { L t; sf("%ld",&t); while(t--) { ull x,y; sf("%llu %llu",&x,&y); ull result = reverse_num(x) + reverse_num(y); pf("%llu\n",reverse_num(result)); } return 0; }
Comments
Post a Comment