#36443: 我不懂這樣會TLE


s11104220@school.saihs.edu.tw (施同學)

學校 : 臺北市立松山高級工農職業學校
編號 : 221254
來源 : [118.165.11.221]
最後登入時間 :
2024-02-04 16:09:17
d098. Stringstream運用練習(C++) -- 說明文件出自C++ Reference | From: [118.165.6.63] | 發表日期 : 2023-07-18 10:34

def main():
    from sys import stdin
    try:
        while True:
            s=stdin.readline().split()
            print(sum(int(i) if i.isdigit() else 0 for i in s))
    except:pass
main()
 
#36444: Re: 我不懂這樣會TLE


s11104220@school.saihs.edu.tw (施同學)

學校 : 臺北市立松山高級工農職業學校
編號 : 221254
來源 : [118.165.11.221]
最後登入時間 :
2024-02-04 16:09:17
d098. Stringstream運用練習(C++) -- 說明文件出自C++ Reference | From: [118.165.6.63] | 發表日期 : 2023-07-18 10:40

def main():
    from sys import stdin
    try:
        while True:
            s=stdin.readline().split()
            print(sum(int(i) if i.isdigit() else 0 for i in s))
    except:pass
main()


更不懂的是

改成input()就過了

 
#36453: Re: 我不懂這樣會TLE


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
d098. Stringstream運用練習(C++) -- 說明文件出自C++ Reference | From: [59.115.3.102] | 發表日期 : 2023-07-18 13:38

 
            s=stdin.readline().split()


因為readline()讀到EOF不會產生EOFError,只會回傳空字串,所以你這裡變成無限迴圈了

https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects

 
#36461: Re: 我不懂這樣會TLE


s11104220@school.saihs.edu.tw (施同學)

學校 : 臺北市立松山高級工農職業學校
編號 : 221254
來源 : [118.165.11.221]
最後登入時間 :
2024-02-04 16:09:17
d098. Stringstream運用練習(C++) -- 說明文件出自C++ Reference | From: [118.165.6.63] | 發表日期 : 2023-07-18 19:55

 
            s=stdin.readline().split()


因為readline()讀到EOF不會產生EOFError,只會回傳空字串,所以你這裡變成無限迴圈了

https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects


長知識了

 
ZeroJudge Forum