当前位置:网站首页>刷题-洛谷-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;
}
边栏推荐
猜你喜欢

2022全球开发者中,你的收入排多少?

嵌入式代码如何进行重构?

Basic knowledge of binary tree

【GCN-RS】Towards Representation Alignment and Uniformity in Collaborative Filtering (KDD‘22)

Machine learning strong foundation program 0-4: popular understanding of Occam razor and no free lunch theorem

vim基础操作汇总

Error: cannot find or load main class XXXX

Excel添加按键运行宏

Uncaught SyntaxError: Octal literals are not allowed in strict mode.

In order to improve efficiency, there are various problems when using parallelstream
随机推荐
领域驱动模型设计与微服务架构落地-模型设计
hcip第八天实验
并发编程 — 内存模型 JMM
Introduction and features of numpy (I)
详解浮点数的精度问题
My creation anniversary
0720RHCSA
ESP32-C3 基于Arduino框架下Blinker点灯控制10路开关或继电器组
How to refactor embedded code?
Arrays常用方法
hcip第十天笔记
Prepare for 2022 csp-j1 2022 csp-s1 preliminaries video set
Basic knowledge of binary tree
0715RHCSA
剑指offer专项突击版第10天
6W+字记录实验全过程 | 探索Alluxio经济化数据存储策略
为提高效率使用ParallelStream竟出现各种问题
0720RHCSA
What is your revenue rank among global developers in 2022?
[Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing