2017年11月01日普及组 I Got a Matrix!
生活随笔
收集整理的這篇文章主要介紹了
2017年11月01日普及组 I Got a Matrix!
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Description
給定一個 n?m 的矩陣 A,詢問位于矩陣邊緣的元素之和。所謂矩陣邊緣的元素,就是第一行和最后一行的元素以及第一列和最后一列的元素。
Input
第一行包含兩個整數 n 和 m。
之后 n 行每行包含 m 個整數 A[i,j]。
Output
共一行包含一個整數 ans,表示位于矩陣邊緣的元素之和。
Sample Input
3 3
3 4 1
3 7 1
2 0 1
Sample Output
15
Hint
對于 100% 的數據:n,m ≤ 100
程序:
varn,m,i,j,k:longint;ans:int64; beginassign(input,'matrix.in');assign(output,'matrix.out');reset(input);rewrite(output);readln(n,m);for i:=1 to n dofor j:=1 to m dobeginread(k);if (i=1)or(i=n)or(j=1)or(j=m) then inc(ans,k);end;writeln(ans);close(input);close(output); end.轉載于:https://www.cnblogs.com/YYC-0304/p/9500030.html
總結
以上是生活随笔為你收集整理的2017年11月01日普及组 I Got a Matrix!的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2017年10月21日普及组 简单单词
- 下一篇: 2017年11月01日普及组 I Lik