#include <stdio.h>
int main() {
宣告i為迴圈索引、d為降雨最多天、t為時段索引
int i, d, t;
宣告m,a,n,e為輸入、dm為最大單日雨量、tm為最大時段雨量
double m, a, n, e, dm, tm;
宣告s1,s2,s3,s4為各時段週加總、cur為今日加總
double s1, s2, s3, s4, cur;
初始化加總與最大值變數
s1 = s2 = s3 = s4 = 0;
dm = -1;
tm = -1;
使用迴圈讀取七天的數據
for (i = 1; i <= 7; i++) {
讀取四個時段的降雨量
scanf("%lf %lf %lf %lf", &m, &a, &n, &e);
累加各時段的週總雨量
s1 += m;
s2 += a;
s3 += n;
s4 += e;
計算今日總雨量
cur = m + a + n + e;
如果今日雨量是大於目前紀錄的最大值
if (cur > dm) {
dm = cur;
d = i;
}
}
比較四個時段的週總雨量,找出最大者
tm = s1;
t = 1;
if (s2 > tm) { tm = s2; t = 2; }
if (s3 > tm) { tm = s3; t = 3; }
if (s4 > tm) { tm = s4; t = 4; }
輸出降雨量最多的日子
printf("%d\n", d);
根據時段索引t輸出對應的時段名稱
if (t == 1) printf("morning\n");
else if (t == 2) printf("afternoon\n");
else if (t == 3) printf("night\n");
else printf("early morning\n");
return 0;
}