Advertisement
a53

Rica

a53
Jan 16th, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream f("rica.in");
  4. ofstream g("rica.out");
  5. typedef int NrMare[10010];
  6.  
  7. void AtribMic(NrMare x, int n)
  8. {
  9. x[0]=0;
  10. if(n==0)
  11. x[(x[0]=1)]=0;
  12. else
  13. for(;n;n/=10)
  14. x[++x[0]]=n%10;
  15. }
  16.  
  17. void AtribMare(NrMare Dest, NrMare Sursa)
  18. {
  19. int i;
  20. for(i=0;i<=Sursa[0];i++)
  21. Dest[i]=Sursa[i];
  22. }
  23.  
  24. void Adunare(NrMare A,NrMare B)
  25. /* A <- A+B */
  26. { int i,T=0;
  27.  
  28. if (B[0]>A[0])
  29. { for (i=A[0]+1;i<=B[0];) A[i++]=0;
  30. A[0]=B[0];
  31. }
  32. else for (i=B[0]+1;i<=A[0];) B[i++]=0;
  33. for (i=1;i<=A[0];i++)
  34. { A[i]+=B[i]+T;
  35. T=A[i]/10;
  36. A[i]%=10;
  37. }
  38. if (T) A[++A[0]]=T;
  39. }
  40.  
  41. void Afisare(NrMare n)
  42. {
  43. for(int i=n[0];i>0;--i)
  44. g<<n[i];
  45. }
  46.  
  47. int main()
  48. {
  49. int X;
  50. NrMare n1,n2,n3,n;
  51. f>>X;
  52. if(X==1||X==2)
  53. {
  54. g<<1;
  55. return 0;
  56. }
  57. if(X==3)
  58. {
  59. g<<2;
  60. return 0;
  61. }
  62. AtribMic(n1,1),AtribMic(n2,1),AtribMic(n3,2);
  63. for(int i=4;i<=X;++i)
  64. AtribMare(n,n1),Adunare(n,n2),Adunare(n,n3),AtribMare(n1,n2),AtribMare(n2,n3),AtribMare(n3,n);
  65. Afisare(n);
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement