본문 바로가기
컴퓨터/알고리즘

[SWEA] 1288. 새로운 불면증 치료법(비트마스크)

by IT황구 2021. 2. 1.
728x90
반응형

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV18_yw6I9MCFAZN

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com


#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;
int main(void)
{
	// 0 ~9 까지니까 1023이면 될듯. 
	int size,n;
	int result,temp,digit;
	int mul;
	scanf("%d",&size);
	for(int i = 0; i < size; i++)
	{
		scanf("%d",&n);
		result = 0;
		temp = n;
		mul = 1;
		while(1)
		{
			while(temp){
				digit = temp % 10;
				result |= 1 << digit;
				temp /= 10;
			}
			if(result == 1023) break;
			mul++;
			temp = n * mul;
			
		}
		printf("#%d %d\n",i+1,n*mul);
	
	}
	return 0;
}

해결 방법:

0,1,2,3,4,5,6,7,8,9가 다 나오면 끝인건데...

지난번에 했던 스도쿠 검증과 똑같다.

이번엔 0이 추가되었으므로, 비트가 0011 1111 1111 이 나와야한다.

1 << 0 이 1 이므로...

따라서 1023인가? 를 확인해주면 된다.

---END---

 

728x90
반응형