문제해설
- 알고리즘 자체보다는 문자열 문제
- what does the fox say? 가 나올 때 문자열을 종료시켜주는 것
- StringToken 잘 쓰기. -->
Java
package Z_ShinHanCard_Prepare;
import java.util.*;
import java.io.*;
/*
* 1
toot woof wa ow ow ow pa blub blub pa toot pa blub pa pa ow pow toot
dog goes woof
fish goes blub
elephant goes toot
seal goes ow
what does the fox say?
* */
public class D4백준9536_여우는어떻게울지
{
public static void main(String[] args) throws Exception
{ String question="what does the fox say?";
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
int T = Integer.parseInt(input);
String s[]= new String[T];
Vector<String> animals = new Vector<String>();
StringTokenizer st;
for(int i = 0 ; i <T ; i++)
{
animals.clear();
input = br.readLine();
s[i]=input; //동물소리 입력받음
for(int j= 0 ; j<100 ; j++)
{
String temp =br.readLine();
if(temp.equals(question))
{
break;
}
st =new StringTokenizer(temp," ");
int tempCout =st.countTokens();
for(int w= 0 ; w<st.countTokens() ;j++) {
if(st.nextToken().equals("goes"))
{
animals.add(st.nextToken());
}
}
}
st=new StringTokenizer(s[i]," ");
while (st.hasMoreTokens())
{
int check=0;
String animal = st.nextToken();
for (int k=0; k<animals.size(); k++)
{
if (animal.equals(animals.get(k)))
{
check=1;
break;
}
else check=0;
}
if (check==0) {
System.out.print(animal+ " ");
}
}
}
}
}
'Algorithm' 카테고리의 다른 글
[백준] 2110 공유기 설치 (이분탐색) C++ (0) | 2020.10.06 |
---|---|
[백준 14888] 연산자 끼워넣기(C++, Java) (0) | 2020.09.09 |
[백준 1654] 랜선 자르기_이분탐색 (0) | 2020.09.07 |
[백준 9012] 괄호 (Java) (0) | 2020.09.07 |
[백준 7562] 나이트의 이동 (C++, Java) (0) | 2020.09.07 |