fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, c;
  6. cin >> n >> c;
  7. const int ten = 10;
  8. int nouNumar = 0;
  9. int number = 0;
  10. int repetari = 0;
  11. while (n > 0) {//here we find what is the new number but in mirror
  12. number = n % ten;
  13. if (number != c) {
  14. nouNumar = (nouNumar + number) * ten;
  15. if (n < ten) {
  16. nouNumar /= ten;
  17. }
  18. }
  19. number = 0;
  20. n /= ten;
  21. }
  22. //we reverse the mirror
  23. int mirror = 0, i = 0;
  24. while (nouNumar > 0) {
  25. i = nouNumar % ten;
  26. mirror = (mirror + i) * ten;
  27. if (nouNumar < ten) {
  28. mirror /= ten;
  29. }
  30. nouNumar /= ten;
  31. }
  32. if (mirror == 0) {
  33. mirror = -1;
  34. }
  35. cout << mirror;
  36. return 0;
  37. }
Success #stdin #stdout 0s 5304KB
stdin
2222222
2









stdout
-1