Odd and Even Sum Calculator


Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 10M

Author:
Problem type

Description

請撰寫一個程式,持續讀取使用者輸入的正整數,並使用 for loop 分別累加奇數與偶數。


Requirements

  1. 輸入

    • 多筆正整數,輸入方式不限,可為一行或多行
    • 當讀到 -1 時,停止輸入
  2. 規則

    • 輸入皆為正整數或 -1,奇數不可被 2 整除,偶數則反之
    • 奇數:1, 3, 5, ...
    • 偶數:2, 4, 6, ...
  3. 輸出

    • 第一行:奇數總和
    • 第二行:偶數總和

Input / Output

Sample 1 Sample 2 Sample 3
INPUT 1 2 3 4 5 -1 2 4 6 8 -1 7 9 11 2 4 -1
OUTPUT 9
6
0
20
27
6

Comments

There are no comments at the moment.