Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 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.  
  17.  
  18. };
  19. class Numereunu{
  20. private:
  21. int nr;
  22. public:
  23. Numereunu(int nr)
  24. {
  25. this->nr=nr;
  26. }
  27.  
  28. };
  29. */
  30.  
  31. int main() {
  32. float ok=0,nr=0;
  33. int n,g,i,j,k=0;
  34. vector <int> numerezero;
  35. vector <int> numereunu;
  36. int v[50];
  37. float rapzero,rapunu;
  38.  
  39. cin>>n>>g;
  40. for (i=0;i<n;i++)
  41. {
  42. cin>>v[i];
  43. }
  44.  
  45. if (n%g==0)
  46. {nr=(float)n/(float)g;}
  47. else {nr=(float)n/(float)(g+1);}
  48.  
  49. for(k=0;k<(int)nr;k++)
  50. {
  51. for (j=k*g;j<(k+1)*g;j++)
  52. {
  53. if (v[j]==1) ok++;
  54. }
  55. if (ok==0)
  56. {
  57. numerezero.push_back(0);
  58. }
  59. else {
  60. numerezero.push_back(1);
  61. for (j=k*g;j<(k+1)*g;j++)
  62. {
  63. numerezero.push_back(v[j]);
  64. }
  65.  
  66. }
  67. ok=0;
  68. }
  69.  
  70. rapzero=(float)(n)/numerezero.size();
  71. rapunu=(float)numereunu.size()/n;
  72.  
  73. if (rapzero>=rapunu)
  74. {
  75. cout<<fixed<<setprecision(2);
  76. cout<<rapzero<<endl;
  77. for (i=0;i<numerezero.size();i++)
  78. { cout<<numerezero[i]<<endl; }
  79. }
  80. else if (rapzero<rapunu)
  81. {
  82. cout<<fixed<<setprecision(2);
  83. cout<<rapunu<<endl;
  84. for (i=0;i<numereunu.size();i++)
  85. { cout<<numereunu[i]<<endl; }
  86. }
  87.  
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement