fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int multiplication(int x) {
  5. int mul = 1;
  6. while(x != 0) {
  7. mul *= x % 10;
  8. x /= 10;
  9. }
  10. return mul;
  11. }
  12. int main() {
  13. int n;
  14. cin >> n;
  15. int maxmul = multiplication(n);
  16. int copy = n;
  17. int i = 10;
  18. while(n != 0) {
  19. int temporary_number = (copy / (i / 10)) % 10;
  20. int left = copy / i;
  21. int right = copy % (i / 10);
  22. if(temporary_number != 9) {
  23. temporary_number = 9;
  24. copy = ((left - 1) * 10 + temporary_number) * (i / 10) + right;
  25. }
  26. n /= 10;
  27. i *= 10;
  28. int mul = multiplication(copy);
  29. if(maxmul < mul) maxmul = mul;
  30. }
  31. cout << maxmul;
  32. }
Success #stdin #stdout 0s 4388KB
stdin
28994
stdout
10368