首先看牛客網的樣例:https://www.nowcoder.com/questionTerminal/dae9959d6df7466d9a1f6d70d6a11417spa
計算a+b的和,每行包行兩個整數a和b,對於每行輸入對應輸出一行a和b的和,距離:code
輸入blog
1 5 get
2 6it
輸出io
6function
8class
while(line=readline()){ var lines = line.split(' '); var a = parseInt(lines[0]); var b = parseInt(lines[1]); function add(m,n){ return m+n; } print(add(a,b)); }
V8實現多行輸入:di
//多行輸入舉例 //打印一個多行矩陣 var n = parseInt(readline()); var ans = 0; for(var i = 0;i < n; i++){ lines = readline().split(" ") for(var j = 0;j < lines.length; j++){ ans += parseInt(lines[j]); } print(ans); }