CCF 201812-1 Xiaoming went to school (score of 100)

CCF 201812-1 Xiaoming goes to school

#include<iostream>

using namespace std;

int main() // k=0,k=1时加上t,k=2时加上t+r,k=3时加上0。
{          // 黄灯后是红灯
	int r, y, g;
	cin >> r >> y >> g;
	int n; // 小明总共经过的路段数和看到的红绿灯数目
	cin >> n;
	int k, t, sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> k >> t;
		if (k == 0) sum += t;
		else {
			if (k == 1) sum += t;
			else {
				if (k == 2) sum += t + r;
				else sum += 0;
			}
		}
	}
	cout << sum << endl;

	return 0;
}

According to the meaning of the title, there is a point implicit in the title: a yellow light is followed by a red light, which needs to be considered.

Published 7 original articles · liked 0 · visits 72

Guess you like

Origin blog.csdn.net/qq_27538633/article/details/105502206