Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bitset>
- #include <math.h>
- using namespace std;
- int N = 0;
- int toiDa = 0;
- int main(){
- int soHe10;
- cin >> soHe10;
- bitset<21> chuyenBinary(soHe10); //chuyen tu interger -> binary
- for (int soTruoc = 0;soTruoc <= 21;soTruoc += 1) {
- if(chuyenBinary[soTruoc] == 1){ //count if = 1
- N += 1;
- }
- else if(toiDa < N && chuyenBinary[soTruoc] == 0){ //reset if = 0 and set toi da
- toiDa = N ;
- N = 0;
- }
- else{ //deo can` thiet :))
- N = 0;
- }
- }
- cout << toiDa;
- }
Advertisement
Add Comment
Please, Sign In to add comment