Skip to content

Instantly share code, notes, and snippets.

@invatainfo
Created February 15, 2020 16:07
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/d12b6441209ad53f2f6e691c08806036 to your computer and use it in GitHub Desktop.
Save invatainfo/d12b6441209ad53f2f6e691c08806036 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
void duplicare(int n, int &d) {
int p = 1, are_cifre_impare = 0;
d = 0;
while (n > 0) {
int ultima_cifra = n % 10;
if (n % 2 == 1) {
are_cifre_impare = 1;
d = p * ultima_cifra + d;
p = p * 10;
}
d = p * ultima_cifra + d;
p = p * 10;
n = n / 10;
}
// daca nu are cifre impare
if (are_cifre_impare == 0) {
d = -1;
}
}
int main() {
int n, d;
cin >> n;
duplicare(n, d);
cout << d << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment