1. 程式人生 > 實用技巧 >【Python】I/O和比賽的其他一些問題

【Python】I/O和比賽的其他一些問題

I/O輸入輸出

#輸入一個字串分割並轉化成n個int數值
a, b= map(int, input().strip().split())
#如果無固定個字串
try:
  while True:
    a, b= map(int, input().strip().split())
    print(a+b)
except EOFError:
    break
#輸入一個數值轉化為int
#如果接下來輸入t個數值
t =int(input().strip())
t =int(input().strip())
while t > 0:
    a,b=map(int,input().strip().split())
    print(a
+b) t=t-1
#if判斷,遇見什麼什麼結束
while True:
    a, b= map(int, input().strip().split())
    if a==0 and b==0 :
        break
    print(a+b)

---------------------------------------------

#獲取最大值

import sys
i = sys.maxsize

----------------------------------------------

#類函式排序重寫

def cmp(self,other):
    
if self.w <other.w: return 1 elif self.w == other.w: return 0 else: return -1 import functools class Strick(): def __init__(self,l,w): self.l = l self.w = w sorted(li,key = functools.cmp_to_key(cmp))