프로그래밍 공부
BOJ/백준 2857번 FBI 본문
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
|
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를 사용하니 쉽게 풀렸다.
'Problem Solving > Baekjoon Online Judge' 카테고리의 다른 글
BOJ/백준 2576번 홀수 (0) | 2019.05.16 |
---|---|
BOJ/백준 2566번 최댓값 (0) | 2019.05.16 |
BOJ/백준 3058번 짝수를 찾아라 (0) | 2019.05.16 |
BOJ/백준 17174번 전체 계산 횟수 (0) | 2019.05.16 |
BOJ/백준 17173번 배수들의 합 (0) | 2019.05.16 |
Comments