※ 引述《Nessa1103 (紫藤)》之銘言:
: ※ [本文轉錄自 Wanted 看板 #1L019pP7 ]
: 作者: Nessa1103 (紫藤) 看板: Wanted
: 標題: [徵求] 請幫我看我程式習題理解得對不對
: 時間: Wed Mar 11 18:01:20 2015
: 有個程式語言的習題要求如下:
: Description
: We want to calculate a sum of squares of some integers, excepting negatives
: The first line of the input will be an integer N (1 <= N <= 100)
: Each of the following N test cases consists of one line containing an integer
: X (0 < X <= 100), followed by X integers (Yn, -100 <= Yn <= 100)
: space-separated on the next line
: For each test case, calculate the sum of squares of the integers excepting
: negatives, and print the calculated sum to the output. No blank line between
: test cases
: (Take input from standard input, and output to standard output)
: 他的意思是要我把他給的輸入範例除了負的以外通通平方加起來嗎?
: 因為他「輸入」的範例給了五行,可是輸出的部分只有兩行。
: 因為這部分卡住,所以不知道該怎麼寫。
應該像是右邊這個樣子 輸入
(顏色是我上的方便解說) 2
6
淺藍色的 2 表示下面一共有兩組 4 8 15 16 23 42
4
這即是題目敘述的 N 55 66 95 27
而一組是什麼呢? 輸出
包含一個數字 X 在單獨一行 2854
17135
以及 X 個數字 Yn 在下面那一行
右邊黃色跟紫色就各是一組
第一組 X=6, 六個數字分別是 4, 8, 15, 16, 23, 42
第二組 X=4, 四個數字分別是 55, 66, 95, 27
而輸出則是對每一組輸出一行表示計算結果
這輸出表示黃色那一組的結果是 2854 (=4^2+8^2+15^2+16^2+23^2+42^2)
紫色那一組的結果是 17135 (=55^2+66^2+95^2+27^2)
那 N 也有可能不是 2 而是更多的數字
如果那個 2 變成 5 那接下來就會有五組, 輸出也要有五行
變成 100 那接下來會有一百組, 輸出要有一百行這樣