2022. 1. 17. 08:30ㆍ알고리즘/백준
문제
It gets tiring, looking for all ways in which the word ‘problem’ can be used (and mis-used) in the news media. And yet, that’s been your job for several years: looking through news stories for that word. Wouldn’t it be better if you could automate the process?
입력
Each line of input is one test case. Lines are at most 80 characters long. There are at most 1000 lines of input. Input ends at end of file.
출력
For each line of input, print yes if the line contains ‘problem’, and no otherwise. Any capitalization of ‘problem’ counts as an occurrence.
예제입력1
Problematic pair programming
"There’s a joke that pairs, like fish and house guests, go
rotten after three days," said Zach Brock, an engineering
manager. Working out problems with a pairing partner can be
a lot like working out problems with a significant other.
During one recent rough patch, Jamie Kite, a developer, sat
her partner down for a talk. "Hey, it feels like we’re
driving in different directions," she recalls saying. "It’s
like any relationship," Ms. Kite said. "If you don’t talk
about the problems, it’s not going to work." When those
timeouts don’t solve the problem, partners can turn to
on-staff coaches who can help with counseling. "People who
have been pairing a while, they’ll start acting like old
married couples," said Marc Phillips, one of the coaches.
People can be as much of a challenge as writing software.
(Excerpted from "Computer Programmers Learn Tough Lesson in
Sharing"; Wall Street Journal, August 27, 2012)
예제출력1
yes
no
no
yes
yes
no
no
no
no
yes
yes
no
no
no
no
no
no
문제풀이
import java.util.*;
import java.io.*;
interface Main{
static void main(String[]a) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String str = "";
String regex = "(?i).*problem.*";
while((str = br.readLine()) != null){
if(str.matches(regex)) {
bw.write("yes");
} else {
bw.write("no");
}
bw.newLine();
}
bw.flush();
}
}
한 줄씩 읽어서 문장 안에 problem이 있다면 yes를 출력하고 없다면 no를 출력하면 되는 문제입니다.
EOF일 경우 반복을 종료하고, problem은 대소문자를 구분하지 않습니다.
대소문자를 구분하지 않으므로 정규식 앞에 (?i)를 추가했습니다.
출처 : https://www.acmicpc.net/problem/10491
'알고리즘 > 백준' 카테고리의 다른 글
[백준] 1264번 모음의 개수 Java 문제 풀이 (0) | 2022.01.17 |
---|---|
[백준] 15881번 Pen Pineapple Apple Pen Java 문제 풀이 (0) | 2022.01.17 |
[백준] 10173번 니모를 찾아서 Java 문제 풀이 (0) | 2022.01.14 |
[백준] 14681번 사분면 고르기 C++ 문제 풀이 if문 (0) | 2020.05.06 |
[백준] 3053번 택시 기하학 C++ 문제 풀이 수학 2 (0) | 2020.03.02 |