백준 문제풀이
[백준][비트마스킹] 1094 막대기 c++ 구현
꽁이꽁설꽁돌
2024. 7. 15. 15:49
728x90
반응형
목차
https://www.acmicpc.net/problem/1094
문제
코드 구현 방향
2의 배수인데 경우를 구하는 것이어서 비트마스킹으로 쉽게 풀었다.
켜진 비트수만 세어주면 되는 문제였다.
코드 구현
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<map>
using namespace std;
int n;
int main() {
int cnt = 0;
cin >> n;
for (int i = 0; i < 7; i++ ) {
if ((1 << i) & n)
cnt++;
}
cout << cnt;
return 0;
}
반응형