https://www.acmicpc.net/problem/1972
1972번: 놀라운 문자열
대문자 알파벳으로만 이루어져 있는 문자열이 있다. 이 문자열에 대해서 ‘D-쌍’이라는 것을 정의할 수 있는데, 이 문자열에 포함되어 있는, 거리가 D인 두 문자를 순서대로 나열한 것을 이 문
www.acmicpc.net
//[C++] 백준 문제풀이 (String)
#include <bits/stdc++.h>
bool test(std::string & s){
if (s.length() <= 2) return true;
int diff = 1;
while(diff <= s.length() - 1){
std::unordered_set<std::string> set;
std::string str;
for (int i = 0; i < s.length() - diff; ++i){
str += s[i];
str += s[i + diff];
if (set.find(str) != set.end()) return false;
set.insert(str);
str.pop_back();
str.pop_back();
}
++diff;
}
return true;
}
int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s;
while(true){
std::cin >> s;
if (s == "*") break;
if (test(s)){
std::cout << s << " is surprising.\n";
}
else {
std::cout << s << " is NOT surprising.\n";
}
}
return 0;
}
'백준 문제풀이 > String' 카테고리의 다른 글
[C++] 백준 문제풀이 (String) 11899번 괄호 끼워넣기 (0) | 2023.07.07 |
---|---|
[C++] 백준 문제풀이 (String) 2992번 크면서 작은 수 (0) | 2023.06.29 |
[C++] 백준 문제풀이 (String) 15353 큰 수 A+B (2) (0) | 2023.06.28 |
[C++] 백준 문제풀이 (String) 4659번 비밀번호 발음하기 (0) | 2023.06.28 |
[C++] 백준 문제풀이 (String) 1755번 숫자놀이 (0) | 2023.06.14 |