fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int n, k;
  8. if (!(cin >> n >> k)) return 0;
  9. int cnt = log10(n)+1;
  10. // Using round to prevent floating-point precision issues
  11. int p = round(pow(10, cnt-k));
  12.  
  13. int copy = n;
  14. int fd = copy % p;
  15. int p2 = round(pow(10, k));
  16. int num = fd * p2;
  17. int end = copy / p;
  18.  
  19. // Output the result instead of returning it
  20. cout << num + end << endl;
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 5308KB
stdin
12345
2
stdout
34512