Advertisement
a53

binar1

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