forked from mintuhouse/spoj-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
42-addrev.cpp
48 lines (46 loc) · 826 Bytes
/
42-addrev.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sstream>
using namespace std;
int rev(int n){
/* char N[10];
//itoa(n,N,10);
string s;
stringstream out;
out<<n;
s=out.str();
strcpy(N,s.c_str());
int k=atoi(N);*/
int N[10];
int t=n;
int i=0;
int flag=0;
do{
int p=t%10;
t/=10;
if(p==0 && flag==0) continue;
else{
N[i]=p;
i++;
flag=1;
}
}while(t>0);
int k=0;
for(int j=0;j<i;j++){
k=k*10+N[j];
}
return k;
}
int main(){
int i,N,a,b;
scanf("%d",&N);
for(i=0;i<N;i++){
scanf("%d",&a);
scanf("%d",&b);
//printf("%d %d\n",rev(a),rev(b));
printf("%d\n",rev(rev(a)+rev(b)));
}
return 0;
}