洛谷笔记 - P1085 不高兴的津津

赞美数组、逆推

//洛谷 P1085 不高兴的津津(NOIP2004)
#include<bits/stdc++.h>
using namespace std;
int main(){
	int day,night,zong[7],max,ans,d; //白天时长 晚间时长 一周7天时长的存储数组 最大时长 时间最久的那一天 
	max=0; //归零
	ans=0; //便于在没有该日期时输出0
	for(d=1;d<=7;d++) //正向数据录入
	{
		cin>>day>>night;
		zong[d]=day+night;
	}
	for(d=7;d>=1;d--)//逆向推算(偷懒妙招)
	{
		if(zong[d]>max&&zong[d]>8) //判断值是否最大/是否等于8
		{
			zong[d]=max; //总数最大者为max
			ans=d; //同时max对应的天数为最大日
		}
	}
	cout<<ans<<endl; //结果输出
	return 0;
}
Just Programming With ♥️ & Peace
使用 Hugo 构建
主题 StackJimmy 设计