• Source
    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.  
    19. if((st1.size()==1)&&(st1[0]=='0'))
    20. {
    21. cout<<0<<endl;
    22. continue;
    23. }
    24.  
    25. if((st2.size()==1)&&(st2[0]=='0'))
    26. {
    27. cout<<0<<endl;
    28. continue;
    29. }
    30.  
    31. for(int i=0;i<st1.size()/2;i++)
    32. {
    33. c = st1[i];
    34. st1[i] = st1[st1.size()-i-1];
    35.  
    36. st1[st1.size()-i-1] = c;
    37. }
    38.  
    39. for(int i=0;i<st2.size()/2;i++)
    40. {
    41. c = st2[i];
    42. st2[i] = st2[st2.size()-i-1];
    43.  
    44. st2[st2.size()-i-1] = c;
    45. }
    46.  
    47.  
    48. size=0;
    49. init(ar);
    50. for(int i=0;i<st1.size();i++)
    51. {
    52. carry = 0;
    53. for(int j=0;j<st2.size();j++)
    54. {
    55. tmp = ((st2[j]-'0')*(st1[i]-'0')) + carry+ar[i+j];
    56.  
    57. ar[i+j] = tmp%10;
    58. carry = tmp/10;
    59.  
    60. if((i+j)==size)
    61. size++;
    62. }
    63.  
    64. if(carry>0)
    65. ar[size++] = carry;
    66. }
    67.  
    68. for(int i=size-1;i>=0;i--)
    69. cout<<ar[i];
    70.  
    71. cout<<endl;
    72. }
    73.  
    74. return 0;
    75. }
    76.