Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <iomanip>
  6. using namespace std;
  7.  
  8. class Numerezero{
  9. private:
  10. int nr;
  11. public:
  12. Numerezero(int nr)
  13. {
  14. this->nr=nr;
  15. }
  16. void afisare(int nr)
  17. {
  18. cout<<nr<<endl;
  19. }
  20.  
  21. };
  22. class Numereunu{
  23. private:
  24. int nr;
  25. public:
  26. Numereunu(int nr)
  27. {
  28. this->nr=nr;
  29. }
  30. void afisare(int nr)
  31. {
  32. cout<<nr<<endl;
  33. }
  34.  
  35. };
  36.  
  37.  
  38. int main() {
  39. float ok=0,nr=0;
  40. int n,g,i,j,k=0;
  41. vector <Numerezero> numerezero;
  42. vector <Numereunu> numereunu;
  43. int v[50];
  44. float rapzero,rapunu;
  45.  
  46. cin>>n>>g;
  47. for (i=0;i<n;i++)
  48. {
  49. cin>>v[i];
  50. }
  51.  
  52. if (n%g==0)
  53. {nr=(float)n/(float)g;}
  54. else {nr=(float)n/(float)(g+1);}
  55.  
  56. while(k!=(int)nr)
  57. {
  58. for (j=k*g;j<(k+1)g;j++)
  59. {
  60. if (v[j]==1) ok==1;
  61. }
  62. if (ok==0)
  63. {
  64. numerezero.push_back(0);
  65. }
  66. else {
  67. numerezero.push_back(1);
  68. for (j=k*g;j<(k+1)g;j++)
  69. {
  70. numerezero.push_back(v[j]);
  71. }
  72.  
  73. }
  74. k++;
  75. ok=0;
  76. }
  77.  
  78. rapzero=(float)numerezero.size()/(float)n;
  79. rapunu=(float)numereunu.size()/(float)n;
  80.  
  81. if (rapzero>=rapunu)
  82. {
  83. cout<<fixed<<setprecision(2);
  84. cout<<rapzero<<endl;
  85. for (i=0;i<numerezero.size();i++)
  86. { numerezero[i].afisare(); }
  87. }
  88. else if (rapzero<rapunu)
  89. {
  90. cout<<fixed<<setprecision(2);
  91. cout<<rapunu<<endl;
  92. for (i=0;i<numereunu.size();i++)
  93. { numereunu[i].afisare(); }
  94. }
  95.  
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement