프로그래밍 공부

BOJ/백준 2857번 FBI 본문

Problem Solving/Baekjoon Online Judge

BOJ/백준 2857번 FBI

khj1999 2019. 5. 16. 03:14

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

 

2857번: FBI

문제 5명의 요원 중 FBI 요원을 찾는 프로그램을 작성하시오. FBI요원은 요원의 첩보원명에 FBI가 들어있다.  입력 5개 줄에 요원의 첩보원명이 주어진다. 첩보원명은 알파벳 대문자, 숫자 0~9, 대시 (-)로만 이루어져 있으며, 최대 10글자이다. 출력 첫째 줄에 FBI 요원을 출력한다. 이때, 해당하는 요원이 몇 번째 입력인지를 공백으로 구분하여 출력해야 하며, 오름차순으로 출력해야 한다. 만약 FBI 요원이 없다면 "HE GOT AWAY!"를

www.acmicpc.net

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.*;
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str[] = new String[5];
        int check[] = new int[5];
        int cnt = 0;
        for(int i = 0; i < str.length; i++) {
            str[i] = sc.next();
        }
        for(int i = 0; i < str.length; i++) {
            if(str[i].contains("FBI")) {
                System.out.print(i+1+" ");
                cnt++;
            }
        }
        if(cnt == 0) {
            System.out.print("HE GOT AWAY!");
        }
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

자바에서 지원하는 함수인 contains를 사용하니 쉽게 풀렸다.

Comments