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