백준

5671 호텔 방 번호

불타는강정 2020. 9. 19. 21:44

전부 다 셌다!

 

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;
}