当前位置:网站首页>刷题-洛谷-P1085 不高兴的津津
刷题-洛谷-P1085 不高兴的津津
2022-07-25 13:32:00 【宋向上_UP】
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;
}
边栏推荐
猜你喜欢

Introduction and features of numpy (I)

卷积神经网络模型之——LeNet网络结构与代码实现

R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions

ES6数组去重 new Set()

0715RHCSA

Error: cannot find or load main class XXXX

Uniapp handles background transfer pictures

Basic knowledge of binary tree

The migration of arm architecture to alsa lib and alsa utils is smooth
详解浮点数的精度问题
随机推荐
Redis可视化工具RDM安装包分享
互斥锁、自旋锁、读写锁……理清它们的区别和应用
stable_baselines快速入门
The whole process of 6w+ word recording experiment | explore the economical data storage strategy of alluxio
Jupyter Notebook介绍
并发编程之AQS
Uncaught SyntaxError: Octal literals are not allowed in strict mode.
Numpy快速入门
Django 2 ----- database and admin
The interviewer asked me: how much do you know about MySQL's storage engine?
备战2022 CSP-J1 2022 CSP-S1 初赛 视频集
卷积神经网络模型之——LeNet网络结构与代码实现
How to realize the configuration method of user password free login?
MLIR原理与应用技术杂谈
【GCN-RS】Learning Explicit User Interest Boundary for Recommendation (WWW‘22)
【GCN】《Adaptive Propagation Graph Convolutional Network》(TNNLS 2020)
uniapp处理后台传输图片
HTTP cache tongtianpian, there may be something you want
Leetcode 113. 路径总和 II
0717RHCSA