Advertisement
Guest User

binar1_eu

a guest
Feb 18th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin("binar.in");
  5. ofstream fout("binar.out");
  6. int n, C, x, aux, cnt1;
  7. int countOnes(int nr)
  8. {
  9.     int count1=0;
  10.     while(nr)
  11.     {
  12.         nr = nr & (nr-1);
  13.         count1++;
  14.     }
  15.     return count1;
  16. }
  17. int main()
  18. {
  19.     int i;
  20.     fin>>C>>n;
  21.     if(C==1)
  22.     {
  23.         int maxc1=0, xmax=0;
  24.         for(i=1; i<=n; i++)
  25.         {
  26.             fin>>x;
  27.             aux=x;
  28.             cnt1=countOnes(x);
  29.             if(cnt1>maxc1)
  30.             {
  31.                 maxc1=cnt1;
  32.                 xmax=aux;
  33.             }
  34.             else if(cnt1==maxc1)
  35.                 if(aux > xmax)
  36.                     xmax=aux;
  37.         }
  38.         fout<<xmax<<'\n';
  39.     }
  40.     if(C==2)
  41.     {
  42.         int lc, pozc, lmax, pozmax, cn1;
  43.         fin>>x;
  44.         cn1=countOnes(x);
  45.         lc=1; pozc=1; lmax=1; pozmax=1;
  46.         for(i=2; i<=n; i++)
  47.         {
  48.             fin>>x;
  49.             cnt1=countOnes(x);
  50.             if(cn1 == cnt1)
  51.                 lc++;
  52.             else
  53.             {
  54.                 if(lc > lmax)
  55.                 {
  56.                     lmax=lc;
  57.                     pozmax=pozc;
  58.                 }
  59.                 lc=1;
  60.                 pozc=i;
  61.                 cn1=cnt1;
  62.             }
  63.         }
  64.         if(lc > lmax)
  65.         {
  66.             lmax=lc;
  67.             pozmax=pozc;
  68.         }
  69.         fout<<lmax<<" "<<pozmax<<'\n';
  70.     }
  71.  
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement