Advertisement
Saleh127

UVA 10106

Oct 22nd, 2020
65
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5.  
  6. string multi(string nums1,string nums2)
  7. {
  8. int l1 = nums1.size();
  9. int l2 = nums2.size();
  10. string str( l1 + l2, '0');
  11. for(int i = l1-1; i >= 0; i--)
  12. {
  13. for(int j = l2-1; j >= 0; j--)
  14. {
  15. int p = (nums1[i]-'0')*(nums2[j]-'0') + (str[i+j+1]-'0');
  16. str[i+j+1] = p%10 + '0';
  17. str[i+j] += p/10;
  18. }
  19. }
  20. for(int i = 0; i < l1+l2; i++)
  21. {
  22. if(str[i]!= '0')
  23. {
  24. return str.substr(i);
  25. }
  26. }
  27. return "0";
  28. }
  29.  
  30.  
  31. int main()
  32. {
  33. ios_base::sync_with_stdio(0);
  34. cin.tie(0);
  35. cout.tie(0);
  36.  
  37. string a,c;
  38. while(cin>>a>>c)
  39. {
  40. cout<<multi(a,c)<<endl;
  41. }
  42. return 0;
  43. }
  44.  
Advertisement
RAW Paste Data Copied
Advertisement