fork(2) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. string l1,l2;
  8. int n;
  9. cin >> n;
  10. for(int a=0; a<n; a++)
  11. {
  12. cin >> l1 >> l2;
  13. if(l1=="0" || l2=="0")
  14. {
  15. cout << 0 << endl;
  16. }
  17. else
  18. {
  19. int x=l1.length(),y=l2.length(),d=0,e,**tab=new int *[y],*suma=new int [x+y];
  20.  
  21. for(int a=0; a<y; a++)
  22. {
  23. tab[a]=new int [(x+y)];
  24. for(int c=0; c<(x+y); c++)
  25. {
  26. tab[a][c]=0;
  27. suma[c]=0;
  28. }
  29. }
  30.  
  31. for(int a=0; a<y; a++)
  32. {
  33. e=0;
  34. d++;
  35. for(int c=0; c<x; c++)
  36. {
  37. e++;
  38. tab[a][(x+y)-d-c]+=((l2[y-d]-48)*(l1[x-e]-48));
  39. //tab[a][(x+y)-d-c-1]+=((l2[y-d]-48)*(l1[x-e]-48))/10;
  40. }
  41. }
  42.  
  43. for(int a=(x+y-1); a>=0; a--)
  44. {
  45. for(int c=0; c<y; c++)
  46. suma[a]+=tab[c][a];
  47. if(suma[a]>=10)
  48. {
  49. suma[a-1]=suma[a]/10;
  50. suma[a]%=10;
  51. }
  52. }
  53.  
  54. if(suma[0]!=0)
  55. cout << suma[0];
  56.  
  57. for(int a=1; a<(x+y); a++)
  58. cout << suma[a];
  59.  
  60. cout << endl;
  61.  
  62. for(int a=0; a<y; a++)
  63. delete [] tab[a];
  64.  
  65. delete [] tab;
  66. delete [] suma;
  67. }
  68. }
  69. return 0;
  70. }
  71.  
Success #stdin #stdout 0s 4524KB
stdin
5
4 2
123 43
324 342
0 12
9999 12345
stdout
8
5289
110808
0
123437655