Time limit 1000ms;
Memory limit 262144KB;
Problem Description:
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
问题链接:Try
问题简述:
第一行输入总的房间数n,第二行输入第1间房间已经住了几个人,以及这间房间的容量,第三行与第二行一样,以此类推,要输出同时可以住两个人的房间数。
问题分析:
可以用for循环来考虑检举数据,简单的判断是否还可以住下两个人,输入第一行只有一个数字,输入后按下回车到第二行,第二行的数字之间以空格分开,每行的处理到换行符为止。
程序说明:
用了一个for循环来检举输入的房间原有人数以及容量,用if判断存在房间容量可以同时住下两个人的房间
Virtual Judge通过的C语言程序如下:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n, m;
int main()
{
scanf_s("%d", &n);//输入房间数n
int pi, qi;
for (int i = 1;i <= n;i++)
{
scanf_s("%d%d", &pi, &qi);//people为pi,room capacity为qi
if (qi - pi >= 2)//如果符合这个条件,G和A就可以同住一个房间
m++;
}
printf("%d", m);//m就为G和A可以同住的房间数
return 0;
}