티스토리 뷰
문제링크 : 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으로 체크하여 중복된 값이 존재하는 지 체크하였다.
'백준 > 실버' 카테고리의 다른 글
[백준 2057번] 팩토리얼 분해 (C++) (0) | 2025.07.10 |
---|---|
[백준 17269번] 이름궁합 테스트 (C++) (0) | 2025.07.09 |
[백준 16208번] 귀찮음 (C++) (0) | 2025.07.07 |
[백준 1418번] K-세준수 (0) | 2025.07.07 |
[백준 15719번] 중복된 숫자 (C++) (0) | 2025.07.05 |