fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void init(int ar[])
  5. {
  6. for(int i=0;i<1000;i++)
  7. ar[i] = 0;
  8. }
  9. int main()
  10. {
  11. int carry,size,ar[1000],tmp;
  12. string st1,st2;
  13. char c;
  14.  
  15. while(!feof(stdin))
  16. {
  17. cin>>st1>>st2;
  18. if((st1.size()==1)&&(st1[0]=='0'))
  19. {
  20. cout<<0<<endl;
  21. continue;
  22. }
  23.  
  24. if((st2.size()==1)&&(st2[0]=='0'))
  25. {
  26. cout<<0<<endl;
  27. continue;
  28. }
  29.  
  30. for(int i=0;i<st1.size()/2;i++)
  31. {
  32. c = st1[i];
  33. st1[i] = st1[st1.size()-i-1];
  34.  
  35. st1[st1.size()-i-1] = c;
  36. }
  37.  
  38. for(int i=0;i<st2.size()/2;i++)
  39. {
  40. c = st2[i];
  41. st2[i] = st2[st2.size()-i-1];
  42.  
  43. st2[st2.size()-i-1] = c;
  44. }
  45.  
  46.  
  47. size=0;
  48. init(ar);
  49. for(int i=0;i<st1.size();i++)
  50. {
  51. carry = 0;
  52. for(int j=0;j<st2.size();j++)
  53. {
  54. tmp = ((st2[j]-'0')*(st1[i]-'0')) + carry+ar[i+j];
  55.  
  56. ar[i+j] = tmp%10;
  57. carry = tmp/10;
  58.  
  59. if((i+j)==size)
  60. size++;
  61. }
  62.  
  63. if(carry>0)
  64. ar[size++] = carry;
  65. }
  66.  
  67. for(int i=size-1;i>=0;i--)
  68. cout<<ar[i];
  69.  
  70. cout<<endl;
  71. }
  72.  
  73. return 0;
  74. }
  75.  
Success #stdin #stdout 0s 15240KB
stdin
9876543210987654321098765432109876543210
543210543210543210543210543210543210
stdout
5365042402683006386770447140823546855218922281281677577913517543141137104100
001524075584432991839027579768183342255878386818029410623374882634279060205