Advertisement
a53

Număr întreg periodic

a53
Feb 10th, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=2e5+100;
  4. int arr[maxn];
  5. int main()
  6. {
  7. string s;
  8. int L;
  9. ifstream f("periodic.in");
  10. f>>L;
  11. f>>s;
  12. ofstream g("periodic.out");
  13. if((int)s.size()>=L)
  14. {
  15. bool flag=true;
  16. for(int i=0; i<L; ++i)
  17. {
  18. arr[i]=s[i]-'0';
  19. }
  20. if(s.size()%L==0)
  21. {
  22. bool Acepty=true;
  23. bool stuas=true;
  24. for(int i=L;i<(int)s.size()&&Acepty;i+=L)
  25. {
  26. for(int j=0;j<L&&i+j<(int)s.size();++j)
  27. {
  28. if(arr[j]>s[i+j]-'0')
  29. {
  30. stuas=false;
  31. break;
  32. }
  33. else if(arr[j]<s[i+j]-'0')
  34. {
  35. Acepty=false;
  36. break;
  37. }
  38. }
  39. }
  40. if(stuas)
  41. {
  42. int res=1;
  43. for(int i=L-1;i>=0;--i)
  44. {
  45. res=res+arr[i];
  46. arr[i]=res%10;
  47. res/=10;
  48. if(res&&i==0)
  49. {
  50. flag=false;
  51. }
  52. }
  53. }
  54.  
  55. }
  56. else
  57. {
  58. int res=1;
  59. for(int i=L-1;i>=0;--i)
  60. {
  61. res=res+arr[i];
  62. arr[i]=res%10;
  63. res/=10;
  64. if(res&&i==0)
  65. {
  66. flag=false;
  67. }
  68. }
  69. }
  70. if(!flag||s.size()%L)
  71. {
  72. arr[0]=1;
  73. for(int i=1;i<L;++i)
  74. arr[i]=0;
  75. int tp=s.size()/L+1;
  76. for(int i=0;i<tp;++i)
  77. {
  78. for(int j=0;j<L;++j)
  79. g<<arr[j];
  80. }
  81. g<<'\n';
  82. }
  83. else
  84. {
  85. int tp=s.size()/L;
  86. for(int i=0;i<tp;++i)
  87. {
  88. for(int j=0;j<L;++j)
  89. g<<arr[j];
  90. }
  91. g<<'\n';
  92. }
  93. }
  94. else
  95. {
  96. memset(arr,0,sizeof arr);
  97. arr[0]=1;
  98. for(int i=0;i<L;++i)
  99. g<<arr[i];
  100. g<<'\n';
  101. }
  102. return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement