牛客网&赛码网 输入输出格式

牛客网&赛码网输入输出

最近面临频繁的笔试,美团和携程的笔试题均在赛码网上进行。如果对赛码网的输入输出格式不熟悉,在做编程题的时候很容易陷入深深的自我怀疑,这里对牛客网和赛码网的编程题输入输出格式进行简单说明,并给出官方推荐的标准写法,供自己日后使用,也方便大家参考。
注:本人使用语言为Python,对于其他语言的输入输出写法请参考官方说明。

牛客网

牛客网建议使用sys.stdin.readline()获取输入,使用print()进行输出。

单行输入

import sys
m, n = map(int, sys.stdin.readline().strip().split())
ans = m + n
print(ans)

多行输入,每一行是一个测试样例

import sys 
for line in sys.stdin:
    a = line.strip().split()
    print(int(a[0]) + int(a[1]))

多个测试用例,每个测试用例有多行

输入包含多组测试用例。对于每组测试用例:第一行包含两个整数N和M,在接下来的M行内,每行包括3个整数。要求按照输入格式输出。

import sys
for line in sys.stdin:
	n, m = map(int, line.strip().split())
	print(n, m)
	for i in range(m):
		for line in sys.stdin:
			a, b, c = map(int, line.strip().split())
			print(a, b, c)

牛客网在线判题系统使用帮助

赛码网

赛码网建议使用input()输入。使用sys.stdin.readline()默认会带换行符,所以要strip(’\n’)进行截取,使用sys.stdout.write(res)标准输出。

单个输入,单个输出

input = int(input())
output = input
print(str(output))

单行多个输入,单行多个输出,空格分割

inputs = list(map(int, input().split(" ")))
m, n = inputs[0], input[1]
print(str(m), str(n))

多个测试案例,每个测试案例多行

输入包含多组测试用例。对于每组测试用例:第一行包含两个整数N和M,在接下来的M行内,每行包括3个整数。要求按照输入格式输出。

while 1:
    nm = list(map(int,input().split(" ")))
    N = nm[0]
    M = nm[1]
    print(str(n)+' '+str(m))
    for i in range(m):
        abc = list(map(int, input().split(" ")))
        a, b, c = abc[0], abc[1], abc[2]
        print(str(a)+' '+str(b)+' '+str(c))

赛码网编程题输入输出官方讲解

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值