fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main () {
  6. int n, c, new_n = 0;
  7. cin >> n >> c;
  8. int n1 = n, power_10 = 1, no_digit_n = 0, no_0_finish_n = 1, counter = 0;
  9. while (n1 > 0) { // aflu cea mai mare putere a lui 10 < n
  10. if (n1 % 10 == 0 && counter == no_digit_n && c != 0) {
  11. no_0_finish_n *= 10;
  12. counter++;
  13. }
  14. power_10 *= 10;
  15. n1 /= 10;
  16. no_digit_n++;
  17. }
  18. power_10 /= 10; // CORECTIE OBLIGATORIE! altfel arata cu x 10 mai mult
  19. int no_of_c = 0;
  20. cout << power_10 << " " << no_0_finish_n << "\n";
  21. while (n > 0) {
  22. if (n / power_10 == c) {
  23. no_of_c++;
  24. } else { // != c
  25. new_n = new_n * 10 + n / power_10;
  26. }
  27. n %= power_10, power_10 /= 10;
  28. }
  29. new_n *= no_0_finish_n; // PTR SITUATIILE CAND N SE TERMINA CU ZEROURI
  30. if (no_of_c == no_digit_n) {
  31. cout << -1;
  32. } else {
  33. cout << new_n;
  34. }
  35. return 0;
  36. }
Success #stdin #stdout 0s 5660KB
stdin
30030	    3
stdout
10000 10
0