#29568: java 極簡單解


wer12369qaz15963@gmail.com (dentr)

學校 : 新北市立清水高中
編號 : 174903
來源 : [111.248.152.60]
最後登入時間 :
2022-07-26 15:13:49
a011. 00494 - Kindergarten Counting Game -- UVa494 | From: [219.84.98.239] | 發表日期 : 2022-03-12 16:56

 用語法中的  split() 並使用正則表達式 /W+為分隔 (意思是所有非單詞的字元 即非 [A-Z] [a-z] [0-9])

後面 加一個 + 意思是 可以有多個或單個 作為分隔

然後 把陣列的長度 貼出來 即答案

 

package UVA;

import java.util.Scanner;

public class a011 {
public static void main(String[]args){
Scanner input = new Scanner(System.in);
while (input.hasNextLine()) {
String q = input.nextLine();
String[] q2 = q.split("\\W+");
System.out.println(q2.length);
}
}
}
 
ZeroJudge Forum