fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void read_a_poly(int length){
  5. int i;
  6. int *coeffs;
  7. coeffs = (int *) malloc(length*sizeof(int));
  8. for (i = 0; i < length; i++){
  9. scanf("%d", &coeffs[i]);
  10. }
  11. free(coeffs);
  12. return;
  13. }
  14.  
  15. void multiply_polys(){
  16. int p;
  17. cout << "-1*x^0";
  18. for (p = 1; p < 6; p++){
  19. cout << " + 0*x^"<<p;
  20. }
  21. cout << " + 1*x^6" <<endl;
  22. }
  23.  
  24. int main() {
  25. int length;
  26. scanf("%d", &length);
  27. read_a_poly(length);
  28. scanf("%d", &length);
  29. read_a_poly(length);
  30. multiply_polys();
  31. return 0;
  32. }
Success #stdin #stdout 0s 3476KB
stdin
4  -1 0 0 1
4  1 0 0 1
stdout
-1*x^0 + 0*x^1 + 0*x^2 + 0*x^3 + 0*x^4 + 0*x^5 + 1*x^6