[백준] 10491번 Quite a problem Java 문제 풀이

2022. 1. 17. 08:30알고리즘/백준

728x90
반응형

문제

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

 

10491번: Quite a problem

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

www.acmicpc.net

 

728x90
반응형