PS/BOJ

백준 2857번: FBI (C++)

도비(Doby) 2022. 7. 30. 23:43

https://www.acmicpc.net/problem/2857

 

2857번: FBI

5개 줄에 요원의 첩보원명이 주어진다. 첩보원명은 알파벳 대문자, 숫자 0~9, 대시 (-)로만 이루어져 있으며, 최대 10글자이다.

www.acmicpc.net


Solved By: string

 

substr(pos, cnt)

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

int main(){
    bool flag = true;
    vector<int> res;
    for(int i = 1; i <= 5; i++){
        string s;
        cin >> s;
        for(int j = 0; j < s.length() - 2; j++){
            string tmp = s.substr(j, 3);
            if(tmp == "FBI"){
                flag = false;
                res.push_back(i);
                break;
            }
        }
    }
    if(flag) cout << "HE GOT AWAY!";
    else{
        for(auto i : res) cout << i << ' ';
    }
    return 0;
}