Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("binar.in");
- ofstream fout("binar.out");
- int n,C,x,aux,cnt1;
- int countOnes(int nr)
- {
- int count1=0;
- while(nr)
- {
- nr=nr&(nr-1);
- count1++;
- }
- return count1;
- }
- int main()
- {
- int i;
- fin>>C>>n;
- if(C==1)
- {
- int maxc1=0, xmax=0;
- for(i=1; i<=n; i++)
- {
- fin>>x;
- aux=x;
- cnt1=countOnes(x);
- if(cnt1>maxc1)
- {
- maxc1=cnt1;
- xmax=aux;
- }
- else if(cnt1==maxc1)
- if(aux > xmax)
- xmax=aux;
- }
- fout<<xmax<<'\n';
- }
- if(C==2)
- {
- int lc, pozc, lmax, pozmax, cn1;
- fin>>x;
- cn1=countOnes(x);
- lc=1; pozc=1; lmax=1; pozmax=1;
- for(i=2; i<=n; i++)
- {
- fin>>x;
- cnt1=countOnes(x);
- if(cn1 == cnt1)
- lc++;
- else
- {
- if(lc > lmax)
- {
- lmax=lc;
- pozmax=pozc;
- }
- lc=1;
- pozc=i;
- cn1=cnt1;
- }
- }
- if(lc > lmax)
- {
- lmax=lc;
- pozmax=pozc;
- }
- fout<<lmax<<' '<<pozmax<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement