문제

https://www.acmicpc.net/problem/2857
2857번: FBI
5개 줄에 요원의 첩보원명이 주어진다. 첩보원명은 알파벳 대문자, 숫자 0~9, 대시 (-)로만 이루어져 있으며, 최대 10글자이다.
www.acmicpc.net
코드
#include <iostream>
#include <string>
using namespace std;
int main(){
bool flag = true;
for(int i=1; i<=5; i++){
string s;
cin >> s;
if(s.find("FBI") != -1){
cout << i << '\n';
flag = false;
}
}
if(flag){
cout << "HE GOT AWAY!";
}
return 0;
}
정리
find
size_t find (const string& str, size_t pos = 0) const;
str : 찾고 싶은 문자열
pos : 탐색을 시작하는 위치(index)
특정 string에 위치를 return해주는 함수
만약 일치하는 string이 없다면 npos(-1)를 return
참조
'Beakjoon > string' 카테고리의 다른 글
| [백준] 9417번 최대 GCD (C++) - substr(), find()를 활용해서 특정 문자 기준으로 자르기, Euclidean algorithm (0) | 2022.09.15 |
|---|---|
| [백준] 1551번 수열의 변화 (C++) - stringstream, split (0) | 2022.06.07 |
| [백준] 2998번 8진수 (C++) - str.insert(), str.substr() (0) | 2022.04.27 |
| [백준] 11656번 접미사 배열 (C++) - str.substr() (0) | 2022.03.05 |
| [백준] 10809번 알파벳 찾기 (C++) (0) | 2021.12.29 |