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



//integer overflow is not checked
int ReverseInteger(int n)
{
    bool negative = false;
	if (n<0)
	{
		n = -n;
		negative = true;
	}
    int m=0;

    while(n!=0)
    {
        m = m*10 + n%10;
        n /= 10;
    }
    
    return negative? -m : m;
}

#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
    int n;
	cout <<  (-1%10);
    while(cin>>n)
        cout<<ReverseInteger(n);
    return 0;
}
View Program Text


Test Status