Advertisement
STANAANDREY

BAC 4/2022 1 ***

Apr 20th, 2022
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void duplicare(int n, int &d) {
  5.     int p = 1, ok = 0;
  6.     d = 0;
  7.     while (n) {
  8.         if (n % 2 == 0) {
  9.             d = (n % 10) * p + d;
  10.             p *= 10;
  11.         } else {
  12.             d = (n % 10) * p + d;
  13.             p *= 10;
  14.             d = (n % 10) * p + d;
  15.             p *= 10;
  16.             ok = 1;
  17.         }
  18.         n /= 10;
  19.     }
  20.     if (!ok) {
  21.         d = -1;
  22.     }
  23. }
  24.  
  25. int main() {
  26.     int d;
  27.     duplicare(23450, d);//2334550
  28.     cout << d << endl;
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement