P1085 不高兴的津津-C语言
1、题目
2、解题过程
(1)第一次 week[i] > week[i-1] 逻辑错误
结果:20
代码:
//洛谷 P1085 不高兴的津津
#include <stdio.h>
#define DAYS 7
int main() {
int week[DAYS];//每周时长
int u, v;//课内和课外时长
int i;
int max;//最长上课时长
int max_day;//最长上课时长的日期
for (i = 0; i < DAYS; i++) {
scanf_s("%d %d", &u, &v);
week[i] = u + v;//每日总时长
if (i == 0) {
max = week[i];
max_day = i;
}
else if (week[i] > week[i-1]) {
max = week[i];
max_day = i;
}
}
if (max > 8) {
printf("%d", max_day +1 );//不高兴程度最高
}
else {
printf("0");
}
return 0;
}
(2)第二次 week[i] > max
结果:
代码:
//洛谷 P1085 不高兴的津津
#include <stdio.h>
#define DAYS 7
int main() {
int week[DAYS];//每周时长
int u, v;//课内和课外时长
int i;
int max;//最长上课时长
int max_day;//最长上课时长的日期
for (i = 0; i < DAYS; i++) {
scanf("%d %d", &u, &v);
week[i] = u + v;//每日总时长
if (i == 0) {
max = week[i];
max_day = i;
}
else if (week[i] > max) {
max = week[i];
max_day = i;
}
//printf("第%d天学习的时长:%d。最大时长是%d,不高兴程度最高是%d", i + 1, week[i],max,max_day+1);
}
if (max > 8) {
printf("%d", max_day +1 );//不高兴程度最高
}
else {
//printf("\n 0");
printf("0");
}
return 0;
}