ACM模式(python)

ACM模式OJ或者笔试

每个例子:第一行是整数,表示长度
第二行是多个整数


'''
Input()打印提示字符串(如果给定)到标准输出,并从标准输入中读取字符串,尾部换行符被剥离。如果用户输入EOF,会触发EOFError。
请注意,Python3中input()一次读取一行,并当作字符串,与Python2中的raw_input()相同
Python的输入是野生字符串,所以要自己转类型
strip去掉首尾的空格和换行符(默认时),返回str
slipt把字符串按空格拆开(默认时),返回[str]
map把list里面的值映射到指定类型,返回[type]'''

while True:
    try:
#         length = list(map(int, input().strip().split()))    # 不要忘记最外边的 list() 否则是个map对象
#         length = length[0]
        length = int(input())    # 一个数字可以这样

    except EOFError:
        break
    
    nums = list(map(int, input().strip().split()))
    
    print(length)

参考:
https://www.cnblogs.com/lfri/p/10373431.html
https://blog.csdn.net/Fire_to_cheat_/article/details/89070451
https://www.codeleading.com/article/53955599915/
Python map()函数将一个全部为int的列表,转化为全部为str的列表

posted @ 2022-02-27 09:25  麦克斯的园丁  阅读(1423)  评论(0编辑  收藏  举报