fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_SIZE = 9;
  5.  
  6. void countDigits(int fr[], int num) {
  7. const int TEN = 10;
  8. do {
  9. ++fr[num % TEN];
  10. num /= TEN;
  11. } while (num);
  12. }
  13.  
  14. int greatestCommonEvenDigit(const int fr[]) {
  15. for (int i = MAX_SIZE; i >= 0; --i) {
  16. if (fr[i] > 1 && i % 2 == 0) {
  17. return i;
  18. }
  19. }
  20. return -1;
  21. }
  22.  
  23. int commonEvenDigit(int n, int m) {
  24. int fr[MAX_SIZE + 1] = {0};
  25. countDigits(fr, n);
  26. countDigits(fr, m);
  27. return greatestCommonEvenDigit(fr);
  28. }
  29.  
  30. int main() {
  31. int n, m;
  32. cin >> n >> m;
  33. int commonDigit = commonEvenDigit(n, m);
  34. if (commonDigit >= 0) {
  35. cout << commonDigit;
  36. } else {
  37. cout << "Experimentul a eșuat";
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5288KB
stdin
100043000 100030400
stdout
4