https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWqPvqoqSLQDFAT_
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Solution {
static int T;
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br = new BufferedReader(new StringReader(src));
T = Integer.parseInt(br.readLine());
for(int t=1; t<=T; t++) {
StringBuilder sb = new StringBuilder("#"+t+" ");
int line = Integer.parseInt(br.readLine());
String data = "";
while((data+=br.readLine()).split("[.?!]").length<line) {
//data+=br.readLine();
}
String [] splited = data.split("[.?!]");
System.out.println(Arrays.toString(splited));
for(String s: splited) {
StringTokenizer tokens = new StringTokenizer(s);
int cnt = 0;
while(tokens.hasMoreTokens()) {
if(isName(tokens.nextToken())) {
cnt++;
}
}
sb.append(cnt).append(" ");
}
System.out.println(sb);
}
}
public static boolean isName(String word) {
return word.matches("^[A-Z][a-z]{0,}$");
}
static String src = "3\r\n" +
"2\r\n" +
"Annyung Hasae Yo! LoL!\r\n" +
"3\r\n" +
"my name is Hye Soo. my id is\r\n" +
"Rhs0266. what your id Bro?\r\n"
+ "1\r\n"
+ "Aa!";
}
초창기 코드의 문제점
String data = "";
while(data.split("[.?!]").length<line) {
data+=br.readLine();
}
"".split("[.?!]")는 length가 0인 문자열을 가지는 배열 리턴!! 따라서 1 문장인 경우 처리하지 못하는 문제 발생