본문 바로가기

백준

5671 호텔 방 번호

전부 다 셌다!

 

n ~ m 사이의 숫자를 문자열로 바꾼 뒤 한 자리씩 확인했다.

 

숫자 중복되는 거 확인하는 부분은 count 배열을 따로 만든 뒤 자릿수를 세는 방식으로 구현했음

 

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <bitset>

#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()

using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;


int     main()
{
    int n, m;
    while (cin >> n >> m)
    {
        int ans = 0;
        for (int i = n; i <= m; i++)
        {
            string s = to_string(i);

            vector<int> count(10);
            bool check = false;
            for (int j = 0; j < s.size(); j++)
            {
                count[s[j] - '0']++;
                if (count[s[j] - '0'] > 1)
                {
                    check = true;
                    break;
                }
            }
            if (check)
                continue;

            ans++;
        }
        cout << ans << endl;
    }

    return 0;
}

'백준' 카테고리의 다른 글

14923 미로 탈출  (0) 2020.09.20
18291 비요뜨의 징검다리 건너기  (0) 2020.09.19
16926 배열 돌리기 1  (0) 2020.09.19
17502 클레어와 팰린드롬  (0) 2020.09.19
16935 배열 돌리기 3  (0) 2020.09.16