Programming Solve/BOJ

BOJ 9342 - 염색체 / C++

msm1029 2022. 4. 10. 17:47
반응형

문제 링크 : https://www.acmicpc.net/problem/9342

 

9342번: 염색체

상근이는 생명과학 연구소에서 염색체가 특정한 패턴인지를 확인하는 일을 하고 있다. 염색체는 알파벳 대문자 (A, B, C, ..., Z)로만 이루어진 문자열이다. 상근이는 각 염색체가 다음과 같은 규칙

www.acmicpc.net

 

 

풀이

주어진 조건대로 정규표현식을 만들어 일치하면 "Infected!"를 일치하지 않으면 "Good"을 출력하면 된다.

 

 

코드

#include <iostream>
#include <regex>
#include <string>
using namespace std;

int main() {
    int n;
    cin >> n;
    regex re("^[A-F]?A+F+C+[A-F]?");

    for(int i=0; i<n; i++){
        string str;
        cin >> str;

        if(regex_match(str, re)){
            cout << "Infected!\n";
        }
        else {
            cout << "Good\n";
        }
    }
}
반응형