출처

  • 2022 서강대학교 청정수컵 청정수 Round A번

문제

링크

풀이

#include <cmath>
#include <iostream>
#include <string>
using namespace std;
 
bool solve(void) {
  int n; cin >> n;
  string s; cin >> s;
 
  int cnt = 1;
  for (int i=1; i<n; i++) {
    cnt = (abs(s[i] - s[i-1]) == 1) ? cnt + 1 : 1;
    if (cnt == 5) return true;
  }
  return false;
}
 
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
 
  cout << (solve() ? "YES" : "NO");
  return 0;
}