알고리즘
백준 1972번 놀라운 문자열 C++
영춘권의달인
2023. 2. 25. 11:58
https://www.acmicpc.net/problem/1972
1972번: 놀라운 문자열
대문자 알파벳으로만 이루어져 있는 문자열이 있다. 이 문자열에 대해서 ‘D-쌍’이라는 것을 정의할 수 있는데, 이 문자열에 포함되어 있는, 거리가 D인 두 문자를 순서대로 나열한 것을 이 문
www.acmicpc.net
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
string str;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
while (true) {
cin >> str;
if (str == "*") break;
bool surprise = true;
for (int i = 1; i < str.length(); i++) {
unordered_set<string> us;
for (int j = 0; j < str.length(); j++) {
if (j + i >= str.length()) break;
string tmp = "";
tmp += str[j];
tmp += str[j + i];
auto it = us.find(tmp);
if (it == us.end()) us.insert(tmp);
else surprise = false;
}
}
if (surprise) {
cout << str <<" is surprising.\n";
}
else {
cout << str << " is NOT surprising.\n";
}
}
}