fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void inmulteste(int a[], int x, int rezultat[]) {
  5. const int TEN = 10;
  6. int i = 1, counter = 0, anteriorRest = 0, newRest = 0;
  7. while (i <= a[0]) {
  8. newRest = (a[i] * x + anteriorRest) / TEN;
  9. rezultat[i] = (a[i] * x + anteriorRest) % TEN;
  10. ++counter;
  11. anteriorRest = newRest;
  12. ++i;
  13. }
  14. while (anteriorRest > 0) {
  15. ++rezultat[a[0]] = anteriorRest % TEN;
  16. ++counter;
  17. anteriorRest /= TEN;
  18. }
  19.  
  20. rezultat[0] = counter;
  21. for (i = 0; i <= counter; ++i) {
  22. cout << rezultat[i] << " ";
  23. }
  24. }
  25. int main() {;
  26. int MAX_SIZE = 1000;
  27. int a[MAX_SIZE + 1], x, rezultat[MAX_SIZE + 1] = {0};
  28. cin >> x;
  29. for (int i = 0; i <= a[0]; ++i) {
  30. cin >> a[i];
  31. }
  32. inmulteste(a, x, rezultat);
  33. return 0;
  34. }
  35.  
  36.  
Success #stdin #stdout 0.01s 5460KB
stdin
3
5 1 2 2 5 8
stdout
6 3 6 6 5 2 0