Created
February 15, 2020 16:07
-
-
Save invatainfo/d12b6441209ad53f2f6e691c08806036 to your computer and use it in GitHub Desktop.
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 <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