# Link

https://www.acmicpc.net/problem/1526

 

1526번: 가장 큰 금민수

첫째 줄에 N이 주어진다. N은 4보다 크거나 같고 1,000,000보다 작거나 같은 자연수이다.

www.acmicpc.net

 

 

# Code - C++

//
//  BOJ
//  ver.C++
//
//  Created by GGlifer
//
//  Open Source

#include <iostream>
#include <queue>

using namespace std;

#define endl '\n'
#define len(x) (int)(x).length()
#define size(x) (int)(x).size()
#define str(x) to_string(x)
#define error logic_error("line " + str(__LINE__))

// Set up : Definitions
/* None */

// Set up : Global Variables
/* None */

// Set up : Functions Declaration
/* None */


int main()
{
    // Set up : I/O
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // Set up : Input
    int N; cin >> N;

    // Process
    queue<int> Q;
    Q.push(0);

    int ans = -1;
    while (not(Q.empty())) {
        int c = Q.front(); Q.pop();

        if (c > N) continue;
        ans = c;

        Q.push(10*c + 4);
        Q.push(10*c + 7);
    }

    // Control : Output
    cout << ans << endl;
}

// Helper Functions
/* None */

 

 

지적, 조언, 첨언 모두 환영합니다!!!

+ Recent posts