๋ฐ์—”์œผ๋กœ ์„ฑ์žฅ์ค‘ ๐ŸŒฑ

์•Œ๊ณ ๋ฆฌ์ฆ˜/[๋ฐฑ์ค€]

BOJ_5671 : ํ˜ธํ…” ๋ฐฉ ๋ฒˆํ˜ธ (C++)

์จ๋ฐ 2023. 2. 13. 23:57

ํ’€์ด ๋ฐฉ๋ฒ•

 

๊ฐ„๋‹จํ•œ ๋ฌธ์ž์—ด ์ค‘๋ณต ํ™•์ธ ๋ฌธ์ œ์ด๋ฉฐ, ์ˆซ์ž ๋ฒ”์œ„๊ฐ€ ํฌ์ง€ ์•Š์œผ๋ฏ€๋กœ ์™„์ „ ํƒ์ƒ‰์„ ํ†ตํ•ด ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์„๊ฑฐ๋ผ ํŒ๋‹จํ–ˆ๋‹ค.

 

 

 

์ฝ”๋“œ

 

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <limits.h>
#include <regex>
#include <sstream>
#include <tuple>
using namespace std;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    // ๋ฐ˜๋ณต๋˜๋Š” ์ˆซ์ž๊ฐ€ ์—†๊ฒŒ ๋ฐฉ ๋ฒˆํ˜ธ ๋งŒ๋“ค๊ธฐ
    // n๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , m ๋ณด๋‹ค๋Š” ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์•„์•ผ ํ•œ๋‹ค
    // ๋ฐฉ์„ ์ตœ๋Œ€ ๋ช‡ ๊ฐœ ๋งŒ๋“ค ์ˆ˜ ์žˆ์„๊นŒ?

    // -> ๋ธŒ๋ฅดํˆฌํฌ์Šค(์™„ํƒ?)

    int n, m;

    int arr[10] = {0, }; // ๋ฐ˜๋ณต๋˜๋Š” ์ˆซ์ž ์ฒดํฌ
    int cnt = 0; // ์ •๋‹ต ๊ฐœ์ˆ˜
    
    while(cin >> n >> m){ // ์•ˆ์— ๋ฐ˜๋ณต๋ฌธ ํ•˜๋‚˜ ์ถ”๊ฐ€
        int temp = n;
        cnt = 0;
        memset(arr, 0, sizeof(arr));
        
        while(1){

            string str = to_string(temp);

            int check = 0;

            for(int i = 0; i < str.size(); i++){
                arr[str[i] - '0']++;
                if(arr[str[i] - '0'] >= 2){
                    check = 1; // ์ค‘๋ณต๋˜๋Š” ์ˆซ์ž๊ฐ€ ์žˆ์œผ๋ฉด ์ฒดํฌ
                    break;
                }
            }

            if(check == 0){
                cnt++;
            }

            if(temp == m){
                cout << cnt << "\n";
                break;
            }

            n++;
            temp = n;
            memset(arr, 0, sizeof(arr));
        }

    }
    
    return 0;
}

 

 

 

'์•Œ๊ณ ๋ฆฌ์ฆ˜ > [๋ฐฑ์ค€]' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

BOJ_18258 : ํ 2 (C++)  (0) 2023.02.21
BOJ_16208 : ๊ท€์ฐฎ์Œ (C++)  (0) 2023.02.20
BOJ_20114 : ๋ฏธ์•„ ๋…ธํŠธ (C++)  (0) 2023.02.17
BOJ_14929 : ๊ท€์ฐฎ์•„ (SIB) (C++)  (0) 2023.02.14