알고리즘왕/BOJ
[백준/1152/JAVA] 단어의 개수
찌 ㅋ
2020. 3. 18. 00:55
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int count = 0;
String sarr[] = s.split(" ");
for(int i = 0; i<sarr.length; i++) {
if(!sarr[i].isEmpty())
count++;
}
System.out.println(count);
}
}
무려 두 번이나 틀렸음,,
공백의 개수를 세서 계산하는 건 옳지 않은 방법이었음을,,,