#5955: 測試都OK 結果WA = = WHY?


tmaclp (IIN)

學校 : 不指定學校
編號 : 21082
來源 : [180.217.45.180]
最後登入時間 :
2022-09-26 21:29:57

import java.util.Scanner;
class SplitString
{
public static void main(String [] idiot)
{
Scanner input = new Scanner(System.in);
while (input.hasNextLine())
{
String sentence = input.nextLine();
String [] token = sentence.split(" ");
System.out.print(token.length+"\n");
}
}
}
 
 
我自己測試  就算都輸入數字也OK  
但是在第6行
正確答案是21
我的答案卻只有19
WHY?? 
#5956: Re:測試都OK 結果WA = = WHY?


sponge (qd)

學校 : 不指定學校
編號 : 21007
來源 : [114.42.180.252]
最後登入時間 :
2024-05-17 15:52:20

import java.util.Scanner;
class SplitString
{
public static void main(String [] idiot)
{
Scanner input = new Scanner(System.in);
while (input.hasNextLine())
{
String sentence = input.nextLine();
String [] token = sentence.split(" ");
System.out.print(token.length+"\n");
}
}
}
 
 
我自己測試  就算都輸入數字也OK  
但是在第6行
正確答案是21
我的答案卻只有19
WHY?? 


你好

    你用空白來切割字串,好像不合題意。

如果  gfgdf  dfgdfgdf;;ggdfgdf  fghd

你的算法會切成 3 個,依題意應該是 4 個 。

 

希望我沒說錯。

 

#6043: Re:測試都OK 結果WA = = WHY?


tmaclp (IIN)

學校 : 不指定學校
編號 : 21082
來源 : [180.217.45.180]
最後登入時間 :
2022-09-26 21:29:57

import java.util.Scanner;
class SplitString
{
public static void main(String [] idiot)
{
Scanner input = new Scanner(System.in);
while (input.hasNextLine())
{
String sentence = input.nextLine();
String [] token = sentence.split(" ");
System.out.print(token.length+"\n");
}
}
}
 
 
我自己測試  就算都輸入數字也OK  
但是在第6行
正確答案是21
我的答案卻只有19
WHY?? 


你好

    你用空白來切割字串,好像不合題意。

如果  gfgdf  dfgdfgdf;;ggdfgdf  fghd

你的算法會切成 3 個,依題意應該是 4 個 。

 

希望我沒說錯。

 

原來是這樣  THX!
#6244: Re:測試都OK 結果WA = = WHY?


t5220pt (hwa)

學校 : 不指定學校
編號 : 9281
來源 : [114.27.34.157]
最後登入時間 :
2014-04-06 11:41:50

我測試後發現 符號可能有

 

".!, ?;\"0123456789:{}[]@#$%\'^&*()_+/-="

 

這麼多