※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 33172번 문제인 周期文字列 (Cycle String)이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/33172
주어지는 문자열의 길이가 짧다는 점을 눈여겨보자. 문자열의 주기는 첫 문자를 항상 포함해야 한다는 점을 관찰하자.
따라서 주어진 문자열의 앞
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
int N;
string s, ss;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> s;
for (int i = 1; i < N; i++) {
if (N % i) continue;
string tmp = s.substr(0, i); ss.clear();
while (ss.length() < s.length()) ss += tmp;
if (s == ss) {
cout << "Yes";
return 0;
}
}
cout << "No";
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 18270 // C++] Livestock Lineup (0) | 2025.02.06 |
---|---|
[BOJ 3870 // C++] Find the Multiples (0) | 2025.02.05 |
[BOJ 33171 // C++] いずれか片方 (Either, but Not Both) (0) | 2025.02.03 |
[BOJ 33170 // C++] ブラックジャック (Blackjack) (0) | 2025.01.24 |
[BOJ 33169 // C++] 所持金 (Money On Me) (0) | 2025.01.23 |