【題目】 https://zerojudge.tw/ShowProblem?problemid=a002
【C】
#include<stdio.h>
int main(void){
int a, b;
while(scanf("%d %d",&a,&b)!=EOF){
printf("%d\n", a + b);
}
return 0;
}
【C++】
#include<iostream>
using namespace std;
int main(){
int a,b;
while(cin>>a>>b){
cout<<a+b<<endl;
}
return 0;
}
【Python】
import sys
for line in sys.stdin: // 標準輸入一次讀一行,一行中有兩個數字,兩個數字間用一個空格分開。
a,b=line.split()
a,b=int(a),int(b) // 因為讀進來的是str型態,所以要轉換成整數才可以作加減。
print(a+b)
【延伸內容】
1. split用法: https://www.runoob.com/python/att-string-split.html
文章標籤
全站熱搜
