Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5. ifstream in("produsxl.in");
  6. ofstream out("produsxl.out");
  7. void citire(int a[])
  8. {
  9. in>>a[0];
  10. for(int i=1;i<=a[0];i++)
  11. {
  12. in>>a[a[0]-i+1];
  13. }
  14. }
  15. void prod(int a[],int cif,int b[],int s[],int nr)
  16. {
  17. int t=0,i,rez,j;
  18. b[0]=0;
  19. for(i=1;i<=a[0];i++)
  20. {
  21. rez=a[i]*cif+t;
  22. b[i]=rez%10;
  23. t=rez/10;
  24. b[0]++;
  25. }
  26. if(t)
  27. {
  28. b[0]++;
  29. b[b[0]]=t;
  30. }
  31. t=0;
  32. for(i=nr;i<=s[0];i++)
  33. {
  34. rez=s[i]+b[i-nr+1]+t;
  35. s[i]=rez%10;
  36. t=rez/10;
  37. }
  38. for(j=i-nr+1;j<=b[0];j++)
  39. {
  40. s[0]++;
  41. rez=b[j]+t;
  42. s[s[0]]=rez%10;
  43. t=rez/10;
  44. }
  45. if(t)
  46. {
  47. s[0]++;
  48. s[s[0]]=t;
  49. }
  50. }
  51. void afisare(int c[])
  52. {
  53. int i;
  54. for(i=c[0];i>=1;i--)
  55. out<<c[i];
  56. }
  57. int a[101],n,s[300],b[150];
  58. int main()
  59. {
  60. int k=0,cif,nr=0;
  61. citire(a);
  62. in>>n;
  63. while(n)
  64. {
  65. cif=n%10;
  66. n=n/10;
  67. nr++;
  68. prod(a,cif,b,s,nr);
  69. }
  70. afisare(s);
  71.  
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement