🌕🌑🌑🌑🌑
# 題目連結
- 題目連結
- Online Judge
- uDebug
# 題目說明
Time limit: 3.000 seconds
# 題目
Everybody sit down in a circle. Ok. Listen to me carefully.
“Woooooo, you scwewy wabbit!”
Now, could someone tell me how many words I just said?
# Input
Input to your program will consist of a series of lines, each line containing multiple words (at least one). A “word” is defined as a consecutive sequence of letters (upper and/or lower case).
# Output
Your program should output a word count for each line of input. Each word count should be printed on a separate line.
# Sample Input
Meep Meep!
I tot I taw a putty tat.
I did! I did! I did taw a putty tat.
Shsssssssssh ... I am hunting wabbits. Heh Heh Heh Heh ...
# Sample Output
2
7
10
9
# 解題技巧
# Solution
import java.util.*; | |
public class Main{ | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
while(sc.hasNextLine()){ | |
String input = sc.nextLine(); | |
String[] arr = input.split("[^A-Za-z]"); | |
int count = 0; | |
for(String a : arr){ | |
if(a.length() != 0){ | |
count++; | |
} | |
} | |
System.out.println(count); | |
} | |
} | |
} |
單字
** **
!! !!
片語 & 搭配詞
!! !!