Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问2. A+B问题II,里的while1, try, except有什么作用, 为什么去掉这三会不通过。报错信息如下,看都看不懂呜呜 #79

Open
RoseWeHere opened this issue Aug 25, 2023 · 6 comments

Comments

@RoseWeHere
Copy link

========[test0.out]=========
Expected | Yours
-21275 -21275
-33271 -33271
-27504 -27504
4487 4487
0 0
0 0
0 0
36114 36114
23388 23388
31036 31036
58522 58522
52266 52266
25246 25246
45396 45396
5746 5746
31197 31197
8197 8197
14566 14566
15679 15679
47973 47973
16544 16544
62343 62343
38735 38735
28536 28536
46778 46778
29639 29639
18855 18855
20797 20797
29906 29906
36397 36397
35587 35587
31576 31576
34979 34979
52280 52280
11992 11992
51940 51940
38428 38428
48990 48990
36947 36947
41588 41588
45670 45670
46095 46095
23896 23896
36113 36113
7905 7905
17583 17583
16773 16773
49473 49473
25639 25639
19616 19616
28973 28973
33789 33789
52489 52489
15159 15159
37983 37983
27574 27574
16783 16783
50883 50883
37341 37341
33626 33626
33274 33274
32651 32651
14885 14885
19785 19785
16834 16834
17101 17101
21102 21102
42592 42592
41624 41624
36289 36289
32673 32673
35057 35057
36711 36711
45204 45204
37221 37221
12229 12229
30540 30540
57710 57710
44311 44311
39201 39201
26787 26787
12142 12142
22730 22730
27071 27071
35834 35834
21931 21931
26188 26188
45009 45009
32540 32540
60978 60978
48673 48673
34307 34307
36872 36872
34059 34059
35464 35464
38519 38519
55289 55289
35637 35637
17011 17011
32200 32200

==============================
time_space_table:
/1001/sample.in:AC mem=15744k time=71ms
/1001/test0.in:WA mem=15744k time=80ms

@Challis-yin
Copy link
Contributor

想看下你的源代码

@zafirshi
Copy link

zafirshi commented Sep 1, 2023

简单写了一下 @Challis-yin

def main():
    N = int(input())
    for i in range(N):
        l = list(map(int, input().split()))
        print(sum(l))


if __name__ == '__main__':
    main()

不加while-try-except确实过不了,求教原因 @youngyangyang04

@charon2121
Copy link
Contributor

第二题在提示中有写到,输入的数据有多组,也就是说,会持续输入 N 以及后面的a和b,而你的代码只处理了测试数据中的第一组数据。

@RoseWeHere
Copy link
Author

感谢

@zafirshi
Copy link

zafirshi commented Sep 5, 2023

第二题在提示中有写到,输入的数据有多组,也就是说,会持续输入 N 以及后面的a和b,而你的代码只处理了测试数据中的第一组数据。

你好 👋 @charon2121 @youngyangyang04

我的实例代码先读取了要处理的总行数N,即: N = int(input())

之后在下面的for循环中每次都读取新输入行,并转化为List[int],即: l = list(map(int, input().split()))

其实是包含了读取每行测试数据的逻辑

使用while 1+try-except结构是更适合处理输入行数没有给出的情况,此时用try-except结构捕捉while死循环中input()为空的异常,以确保正确退出

此题给出了输入行数N,感觉使用for循环也没有问题

PS:此题和牛客上的输入-输出练习题目:URL 一致,但相同的代码牛客可以AC,卡码网却不能,很困惑 🤔

image
image

@zafirshi
Copy link

zafirshi commented Sep 5, 2023

自答一下 😂

刷到 6. A+B问题VIII,看到下面的Hint知道原因了,

牛客网的输入严格保证了下面的格式

2
2 4
9 21

卡码网上的输入可能会有多组模板输入一股脑输入的情况,即

2
2 4
9 21
2
2 4
9 21
2
2 4
9 21

PS: 感觉有点反直觉 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants