fork download
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int i,j,k,l,p=0,n,m,carry=0;
  6. char *f,*s;
  7. int *ans;
  8. cin>>n;
  9. cin>>m;
  10. f=new char[n+1];
  11. cin.ignore();
  12. cin.getline(f,n+1);
  13. s=new char[m+1];
  14. //cin.ignore();
  15. cin.getline(s,m+1);
  16. ans=new int[m+n+1];
  17. for(i=m-1;i>=0;i--)
  18. {
  19. for(j=n-1,k=p;j>=0;j--,k++)
  20. ans[k]+=(s[i]-48)*(f[j]-48);
  21. p++;
  22. }
  23. for(l=0;l<m+n;l++)
  24. {
  25. ans[l]+=carry;
  26. carry=ans[l]/10;
  27. ans[l]=ans[l]%10;
  28. }
  29. for(l=m+n-1;l>=0;l--)
  30. cout<<ans[l];
  31. return 0;
  32. delete [] s;
  33. delete [] f;
  34. delete [] ans;
  35. }
Success #stdin #stdout 0s 3476KB
stdin
3
2
121
54

stdout
06534