Programming/Baekjoon

백준 1527 c++ [금민수의개수]

fishersheep 2022. 5. 4. 16:52
반응형
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

using namespace std;

long long a, b;
long long answer = 0;

int main()
{	
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> a >> b;	//a,b입력 

	queue<long long>q;	//queue선언
	q.push(4);
	q.push(7);

	while (!q.empty())
	{
		long long num = q.front();
		q.pop();

		if (num >= a && num <= b)answer++;	//num이 a<=num<=b 의조건을 충족한경우 answer증가

		if (num < b)	//최대범위값 보다작은경우
		{
			long long temp = num * 10 + 4;	//*10+4를 한값을 다시 queue에 push
			long long temp2 = num * 10 + 7;
			q.push(temp);
			q.push(temp2);

		}

	}

	cout << answer;	//결과출력

	return 0;
}
반응형

'Programming > Baekjoon' 카테고리의 다른 글

백준 5567 c++ [결혼식]  (0) 2022.05.05
백준 16943 c++ [숫자재배치]  (0) 2022.05.05
백준 1063 c++ [킹]  (0) 2022.05.04
[백준] 2667 단지번호붙이기 c++  (0) 2022.05.03
[백준] 7569 토마토 c++  (0) 2022.05.03