반응형
https://www.acmicpc.net/problem/12924
#문제 간단 정리
문자열을 사용한 구현문제정도
#문제 해결 방법
다른사람들은 어떻게 풀었을지 모르겠지만
일단 문제에서 주어진거처럼
뒤에서 1~ 문자열 길이 만큼 잘라서
앞으로 붙여서 B 보다 작다면 ok
라는 방식으로 직관적으로 구현햇다
대략 길이가 7자리수니까
주어진 범위가 이백만 정도니까 이백만 x 7 해도 문제가 없음을 알 수 있다.
#전체 코드
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>
#include <string>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string sA, sB;
cin >> sA >> sB;
int A = stoi(sA), B = stoi(sB);
int length = (int)sA.size();
long long ans = 0;
for (int x = A; x < B; x++) {
string sx = to_string(x);
unordered_set<int> used;
for (int cutPos = 1; cutPos < length; cutPos++) {
string backPart = sx.substr(length - cutPos);
string frontPart = sx.substr(0, length - cutPos);
string rotated = backPart + frontPart;
if (rotated[0] == '0') continue;
// 회전 결과 정수
int y = stoi(rotated);
if (x < y && y <= B) {
used.insert(y);
}
}
ans += used.size();
}
cout << ans << "\n";
return 0;
}
반응형
'[백준] > C++' 카테고리의 다른 글
백준 14504번 로봇 청소기 [C++] (0) | 2025.01.02 |
---|---|
백준 18114번 블랙 프라이데이 [C++] (0) | 2025.01.01 |
백준 21396번 이진수 더하기 [C++] (1) | 2025.01.01 |
백준 11815번 짝수?홀수? [C++] (0) | 2025.01.01 |
백준 3005번 크로스워드 퍼즐 찾아보기 [C++] (0) | 2025.01.01 |