#29594: zerojudge為什麼不給我測資啊啊啊


Super487 (Super487)

學校 : 國立交通大學
編號 : 182269
來源 : [140.113.92.29]
最後登入時間 :
2023-12-26 20:22:51
a011. 00494 - Kindergarten Counting Game -- UVa494 | From: [220.141.4.148] | 發表日期 : 2022-03-13 13:49

table = 'abcdefghijklmnopqrstuvwxyz '

 

while True:

  try:

    s = input().lower()

    result = ''

    for i in s:

      if i in table:

        result += i

    l = result.split(' ')

    print(len(l))

  except:

    break

 
#29601: Re:zerojudge為什麼不給我測資啊啊啊


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
a011. 00494 - Kindergarten Counting Game -- UVa494 | From: [27.247.4.185] | 發表日期 : 2022-03-13 19:51

table = 'abcdefghijklmnopqrstuvwxyz '

 

while True:

  try:

    s = input().lower()

    result = ''

    for i in s:

      if i in table:

        result += i

    l = result.split(' ')

    print(len(l))

  except:

    break


1. 特殊符號也可能把字分隔開來(我的作法是把特殊符號都改成空格)

2. 可能連續多個空格,這時split()會產生空的元素,造成len太多,可以檢查一下,或者是使用re.split()

3. 字串最前面和最後面的空格要去掉

 
ZeroJudge Forum