Advertisement
a53

ProdusXL

a53
Feb 28th, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <fstream>
  2. #define N 111
  3. using namespace std;
  4. typedef int Huge[N];
  5.  
  6. void Nr_Huge(Huge X,int n) /// X <- n
  7. {
  8. int i=0;
  9. X[0]=0;
  10. if(n==0)
  11. X[0]=1,X[1]=0;
  12. else
  13. while(n)
  14. ++X[0],X[++i]=n%10,n/=10;
  15. }
  16.  
  17. void MultHuge(Huge A,Huge B) /// A <- A x B
  18. {
  19. if(B[0]==1&&B[1]==0) /// Verific daca al doilea numar este 0
  20. {
  21. A[0]=1;
  22. A[1]=0;
  23. return;
  24. }
  25. int i,j,T=0;
  26. Huge C;
  27. C[0]=A[0]+B[0]-1;
  28. for(i=1;i<=A[0]+B[0];)
  29. C[i++]=0;
  30. for(i=1;i<=A[0];++i)
  31. for(j=1;j<=B[0];++j)
  32. C[i+j-1]+=A[i]*B[j];
  33. for(i=1;i<=C[0];++i)
  34. T=(C[i]+=T)/10,C[i]%=10;
  35. if(T)
  36. C[++C[0]]=T;
  37. for(i=0;i<=C[0];++i)
  38. A[i]=C[i];
  39. }
  40.  
  41. int main()
  42. {
  43. int n;
  44. Huge nr_mare,nr_mic;
  45. ifstream f("produsxl.in");
  46. f>>n;
  47. for(int i=1;i<=n;++i)
  48. f>>nr_mare[n-i+1];
  49. nr_mare[0]=n;
  50. int nr;
  51. f>>nr;
  52. f.close();
  53. Nr_Huge(nr_mic,nr);
  54. MultHuge(nr_mare,nr_mic);
  55. ofstream g("produsxl.out");
  56. for(int i=nr_mare[0];i>0;--i)
  57. g<<nr_mare[i];
  58. g<<'\n';
  59. g.close();
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement