牛客網輸入輸出問題(python)

2021-09-23 17:10:45 字數 882 閱讀 3613

1.字串

單行:

import sys

line = sys.stdin.readline().strip()

print(line)#輸出的字串

直接使用input也可以達到相同的效果

line = input()

print(line)#輸出為字串

多行:

import sys

if __name__ == "__main__":

data=

while true:

line = sys.stdin.readline().strip()#此處也可以用input實現

if not line:

break

print("".join(data))

比如輸入12

3輸出:123

2.數字

n=int(input())

print(n)#輸出為數字

3.單行輸入輸出為陣列

l=list(map(int,input().split(" ")))

print(l)

4.輸出形式為矩陣

import sys

if __name__ == "__main__":

data=

while true:

line = sys.stdin.readline().strip()

if not line:

break

tmp = list(map(int, line.split(" ")))

print(data)

牛客網 python輸入輸出要求

牛客網推薦使用sys.stdin.readline 形式輸入,輸出用print 牛客網的一般程式設計題和劍指offer與letcode的輸入輸出格式不同 如 計算兩數的和 python2 獲取輸入 import sys try while true line sys.stdin.readline s...

牛客網python輸入輸出格式

用python刷題 問題 卡在了輸入上 輸入注意 測試用例都是以行的形式輸入的,為了可以正確的讀到測試用例,用python讀取數字時 map int,sys.stdin.readline strip split 牛客網中寫 和用編譯器寫 一樣,所有的格式都需要自己敲,這是和力扣的最大區別 貼上乙個已...

牛客網程式設計題輸入輸出

求a b 前面四行都是一樣的 牛客網 readline 賽碼 read line var print console.log var readline require readline sync readline.setdefaultoptions var read line readline.pr...