题解:这是洛谷的第6道题目,依然考察的是条件语句。最重要的一句是“一天上课超过8个小时就会不高兴,不高兴不会持续到第二天”,因此需要删选不高兴的时间小于8个小时的,以及每天上课时间最长的。
源代码:
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
int main()
{
unsigned int schooltime, mothertime;
unsigned int totaltime = 0, firsttime = 0;
for (int i = 1; i <= 7; i++)
{
cin >> schooltime >> mothertime;
if (totaltime < schooltime + mothertime && schooltime + mothertime>8)
{
totaltime = schooltime + mothertime;
firsttime = i;
}
}
cout << firsttime << endl;
system("pause");
return 0;
}