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
问题简述:
George最近考上了一所大学,他的朋友Alex也考进了,他们想住同一间宿舍,总共有n间宿舍,同时第i个宿舍有pi个人居住,容纳量为qi人,请问有多少间宿舍可以让Geogor和Alex同时入住。
问题分析:
对于每个房间,判断其空床位是否大于等于2,把符合条件的房间数加起来。
程序说明:
输入房间数n后,判断输入的n是否符合要求,符合要求后用for循环输入已入住人数和房间容纳量,再用for循环计算符合条件的房间数
程序实现:
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
int n, i;
cin >> n;
while (n < 1 || n>100)
{
cout << "请输入正确的数" << endl;
cin >> n;
}
int p[i], q[i];
for (i = 0; i < n; i++)
{
cin >> p[i];
cout << " ";
cin >> q[i];
cout << endl;
while (p[i] > q[i] || p[i] < 0 || p[i]>100 || q[i] < 0 || q[i]>100)
{
cout << "输入错误,请重新输入这一次数据" << endl;
cin >> p[i];
cout << " ";
cin >> q[i];
cout << endl;
}
}
int k = 0;
for (i = 0; i < n; i++)
{
if (p[i] < q[i] - 1)
{
k++;
}
}
cout << k;
}