Guest User

Untitled

a guest
Sep 8th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <bitset>
  3. #include <math.h>
  4. using namespace std;
  5. int N = 0;
  6. int toiDa = 0;
  7. int main(){
  8. int soHe10;
  9. cin >> soHe10;
  10. bitset<21> chuyenBinary(soHe10); //chuyen tu interger -> binary
  11. for (int soTruoc = 0;soTruoc <= 21;soTruoc += 1) {
  12. if(chuyenBinary[soTruoc] == 1){ //count if = 1
  13. N += 1;
  14. }
  15. else if(toiDa < N && chuyenBinary[soTruoc] == 0){ //reset if = 0 and set toi da
  16. toiDa = N ;
  17. N = 0;
  18. }
  19. else{ //deo can` thiet :))
  20. N = 0;
  21. }
  22. }
  23. cout << toiDa;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment