Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <fstream>
  2. #include <cmath>
  3. using namespace std;
  4. ifstream fin("binar.in");
  5. ofstream fout("binar.out");
  6. int n,i,x,a,f,j,v[500001],b,k,ap[3],Max,numar,r[500001],c,r2[500001],ok,l,Max2,p;
  7. int main()
  8. {
  9. fin>>c;
  10. fin>>n;
  11. for(i=1;i<=n;i++){
  12. fin>>x;
  13. r[i] = x;
  14. a = 0;
  15. f = 0;
  16. for(j=0;j<=2;j++){
  17. ap[j] = 0;
  18. }
  19. while(x){
  20. a = x % 2;
  21. ap[a]++;
  22. f++;
  23. v[f] = a;
  24. x = x / 2;
  25. }
  26. r2[i] = ap[1];
  27. if(ap[1]>Max){
  28. Max = ap[1];
  29. numar = r[i];
  30. }
  31. else if(ap[1]==Max){
  32. if(r[i]>numar){
  33. numar = r[i];
  34. }
  35. }
  36. k = f - 1;
  37. b = 0;
  38. for(j=f;j>=0;j--){
  39. b = b + v[j]*pow(10,k);
  40. k--;
  41. }
  42. }
  43. if(c==1){
  44. fout << numar << endl;
  45. }
  46. l = 0;
  47. ok = 0;
  48. for(i=1;i<=n;i++){
  49. if(ok==1 && r2[i]==r2[i+1]){
  50. l++;
  51. if(l>Max2){
  52. Max2 = l;
  53. }
  54. }
  55. if(ok==1 && r2[i]!=r2[i+1]){
  56. ok = 0;
  57. l = 0;
  58. }
  59. if(r2[i]==r2[i+1] && ok == 0){
  60. ok = 1;
  61. l++;
  62. if(l>Max2){
  63. Max2 = l;
  64. p = i;
  65. }
  66.  
  67. }
  68. }
  69. if(c==2){
  70. if(p<=0){
  71. p = 1;
  72. }
  73. fout << Max2 + 1 << " " << p << endl;
  74. }
  75.  
  76.  
  77. return 0;
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement