Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- class Solution {
- public:
- int reverse(int x) {
- long long rev = 0;
- while (x)
- {
- rev *= 10;
- rev += (x % 10);
- x /= 10;
- }
- return ((rev > INT_MAX || rev < INT_MIN) ? 0 : rev);
- }
- };
- int main(void)
- {
- cout << "Number to reverse: ";
- int num; cin >> num;
- Solution s;
- int count = 0, original = num;
- while (num % 10 == 0) {
- ++count;
- num /= 10;
- }
- int reverseNum = s.reverse(num);
- cout << "\nReversed Number: ";
- if (reverseNum < 0) {
- cout << "-";
- reverseNum *= (-1);
- }
- for (int i = 0; i < count; i++)
- {
- cout << "0";
- }
- cout << reverseNum << "\n\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement