Skip to content

Instantly share code, notes, and snippets.

@invatainfo
Last active March 26, 2019 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save invatainfo/a99cce39e98567d9c83b9339f527f695 to your computer and use it in GitHub Desktop.
Save invatainfo/a99cce39e98567d9c83b9339f527f695 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void inserare(int& n)
{
int new_n = 0, last_digit, p = 1;
while (n >= 10) {
new_n += (n % 10) * p;
p *= 10;
new_n += abs(n % 10 - (n / 10) % 10) * p;
n = n / 10;
p *= 10;
}
new_n += (n % 10) * p;
n = new_n;
}
int main() {
int n;
cin >> n;
inserare(n);
cout << n << endl;
return 0;
}
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment