Created
April 20, 2014 16:51
-
-
Save swimmi/11118891 to your computer and use it in GitHub Desktop.
Reverse two numbers and add then reverse the sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fstream> | |
#include <iostream> | |
#include <algorithm> | |
#include <sstream> | |
using namespace std; | |
//Reverse two numbers and add then reverse the sum. | |
int main() | |
{ | |
//ifstream cin("adding_reversed_numbers.txt"); | |
int n; | |
cin>>n; | |
for(int i=0;i<n;i++) | |
{ | |
int sum=0; | |
int num; | |
string s; | |
stringstream ss; | |
for(int j=0;j<2;j++) | |
{ | |
cin>>num; | |
ss.clear(); | |
ss<<num; | |
ss>>s; | |
reverse(s.begin(),s.end()); | |
istringstream iss(s); | |
iss>>num; | |
sum+=num; | |
} | |
ss.clear(); | |
ss<<sum; | |
ss>>s; | |
reverse(s.begin(),s.end()); | |
istringstream iss(s); | |
iss>>sum; | |
cout<<sum<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment