SGU[276] Andrew's Troubles

Description

描述

Famous Berland ACM-ICPC team Anisovka consists of three programmers: Andrew, Michael and Ilya. A long time ago, during the first few months the team was founded, Andrew was very often late to the trainings and contests. To stimulate Andrew to be more punctual, Ilya and Andrew decided to introduce a new rule for team participants. If somebody is late (i.e. comes at least one second after appointed time) he owes a cup of tea to other team members. If he is late for 5 minutes, he owes two cups of tea. If he is late for 15 minutes, he owes three cups of tea. And if he is late for 30 minutes or more, he owes 4 cups of tea. 

著名的Berland ACM-ICPC队Anisovka由3个队员组成:Andrew、Michael、Ilya。很久以前,在这个队刚刚成立的前几个月内,Andrew在训练或者比赛时总是迟到。为了使得Andrew更加守时,Ilya和Andrew决定采用一套新的队伍管理方案。如果某人迟到(预定时间后至少一秒),他需要给队员们一杯茶,如果迟到5分钟,需要2杯,如果迟到15分钟,需要3杯,如果迟到30分钟或者更多,需要4杯。

The training starts at the time S (counted in seconds, from some predefined moment of time) and Andrew comes at the time P (also in seconds, counted from the same moment of time). 
Your task is to find how many cups of tea Andrew owes.

训练从S(以秒计时,从某个预定的时刻开始)时刻开始,Andrew在P(以秒计时,从一样的预定时间开始)时刻到达。

你的任务是Andrew需要买多少杯茶。

 

Input

输入

The input file contains single line with integer numbers S and P (0 <= S,P <= 10^4). 

输入文件包含一行两个整数S和P(0 <= S, P <= 10^4)。


Output

输出

Write to the output file the number of cups Andrew owes. 

输出Andrew需要买的茶的杯数。


Sample Input #1

样例输入 #1

10 10


Sample Output #1

样例输出 #1

0

 

Sample Input #2

样例输入 #2

10 11


Sample Output #2

样例输出 #2

1

 

Sample Input #3

样例输入 #3

0 300


Sample Output #3

样例输出 #3

2

 

Analysis

分析

水题。

 

Solution

解决方案

#include <iostream>

using namespace std;

int main()
{
	int S, P;
	while(cin >> S >> P)
	{
		int nDiff = P - S;
		if(nDiff <= 0) { cout << 0 << endl; }
		else if(nDiff >= 1 && nDiff < 300) { cout << 1 << endl; }
		else if(nDiff >= 300 && nDiff < 900) { cout << 2 << endl; }
		else if(nDiff >= 900 && nDiff < 1800) { cout << 3 << endl; }
		else { cout << 4 << endl; }
	}
	return 0;
}

  

练练手。

原文地址:https://www.cnblogs.com/Ivy-End/p/4319796.html