George and Accommodation
Time limit:1000 ms Memory limit:262144 kB
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.
Input
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms.
The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room’s capacity.
Output
Print a single integer — the number of rooms where George and Alex can move in.
Examples
Input
3
1 1
2 2
3 3
Output
0
Input
3
1 10
0 10
10 10
Output
2
问题简述:
两人要住同一个房间,我们可以自定义房间数,目前房间人数和房间容量,计算出房间容量和房间人数的差大于等于二即可让两人住进,要算出可行的房间数量。
问题分析:
可以手动输入房间人数和容量,用if语句判断即可。
程序说明:
手动输入房间数,每个房间人数和每个房间容量,用if语句判断,可行则j+1,最后输出j。
c++语言程序如下:
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
int i, j = 0, n, x, y;
cout << "请输入房间数:";//输入房间数
cin >> n;
for (i = 0; i < n; i++)
{
cout << "请输入第" << i + 1 << "间房的人数和容量:";
cin >> x >> y;//输入房间人数和容量
if (x > y)//若房间人数大于房间容量则跳出循环
{
cout << "房间人数大于房间容量" << endl;
break;
}
if ((y - x) >= 2)
j += 1;//若有合适的房间便让j的值加一
}
cout << "George and Alex可以一起睡的房间数是:" << j << "个" << endl;//输出房间数
}