Advertisement
a53

Error

a53
Mar 31st, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream f("error.in");
  4. ofstream g("error.out");
  5. typedef int NrMare[1010];
  6. NrMare x,y;
  7. int n,a,b;
  8.  
  9. void Adunare(NrMare x,NrMare y)
  10. /// x = x + y
  11. {
  12. int i,t=0;
  13. if(x[0]<y[0])
  14. x[0]=y[0];
  15. for(i=1;i<=x[0];i++,t/=10)
  16. {
  17. t=x[i]+y[i]+t;
  18. x[i]=t%10;
  19. // echivalent x[i]=(t+=x[i]+y[i])%10
  20. }
  21. if(t)
  22. x[++x[0]]=t;
  23. }
  24.  
  25. int main()
  26. {
  27. f>>n;
  28. x[0]=1;
  29. x[1]=0;
  30. for(int i=1;i<=n;++i)
  31. {
  32. f>>a>>b;
  33. y[0]=30;
  34. for(int j=1;j<=30;++j)
  35. a%=b,a=a*10,y[30-j+1]=a/b;
  36. Adunare(x,y);
  37. }
  38. for(int i=30;i>10;--i)
  39. g<<x[i]<<' ';
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement