Rezolvare BAC Informatica 2009 – Varianta 86 – Subiectul al III-lea problema 3
Mai jos puteti gasi rezolvarea problemei 3 de la subiectul III din varianta 86 pentru examenul de bacalaureat din anul 2009
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.h> | |
long numar(long x, int c1, int c2) { | |
long r = 0; | |
while (x) { | |
if (x % 10 == c1) | |
r = r * 10 + c2; | |
else | |
r = r * 10 + x % 10; | |
x = x / 10; | |
} | |
while (r) { | |
x = x * 10 + r % 10; | |
r = r / 10; | |
} | |
return x; | |
} | |
int rec(int x, int c1, int c2) { | |
if (x == 0) | |
return 0; | |
else if (x % 10 == c1) | |
return rec(x / 10, c1, c2) * 10 + c2; | |
else | |
return rec(x / 10, c1, c2) * 10 + x % 10; | |
} | |
void main() { | |
long x; | |
cin >> x; | |
cout << rec(x, 4, 7); | |
} |
Spor la lucru! Daca aveti intrebari nu ezitati sa le lasati in comentarii, va vom raspunde cat de repede putem 