티스토리 뷰

백준/실버

[백준 5671번] 호텔 방 번호 (C++)

게임개발기원 2025. 7. 8. 20:00

문제링크 : https://www.acmicpc.net/problem/5671

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

    int N, M;
    while(cin >> N >> M)
    {
        int cnt = 0;
        for(int i=N; i<=M; i++)
        {
            string s = to_string(i);
            bool flag = 0;
            map<char, int>m;
            for(int j=0; j<s.size(); j++)
            {
                m[s[j]]++;
                if(m[s[j]] > 1)  flag = 1;
            }
            if(!flag) cnt++;
        }
        cout << cnt << '\n';
    }


    return 0;
}

 

입력받은 N~M까지 중복된 숫자를 체크해준다.

해당 값을 문자열로 바꾼 후, 각 값을 map으로 체크하여 중복된 값이 존재하는 지 체크하였다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함