第一期作业第二题

题目:
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.
翻译版:
乔治最近进入了BSUDP(Brand州立大学的酷程序员)。乔治有一个朋友亚历克斯也进了大学。现在他们搬进宿舍了。

乔治和亚历克斯想住在同一个房间里。宿舍总共有N个房间。现在第i个房间里住着π人,这个房间可以容纳齐人(π≤qi)。你的任务是计算乔治和亚历克斯有多少房间。

输入

第一行包含一个整数n(1乘×n=100)-房间数。

接下来的n行的第i行包含两个整数pi和qi(0≤≤pi≤≤qi≤100)——已经住在第i个房间中的人数和房间容量。

产量

打印一个整数-乔治和亚历克斯可以移动的房间数。
代码:

#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
	int room;
	cin >> room;  //输入有多少个房间
	int *a = new int(room);
	int *b = new int(room);
	int i;
	for (i = 0; i < room; i++)
	{
		cin >> a[i] >> b[i];
	}
	int account = 0;
	for (i = 0; i < room; i++)
	{
		if (b[i] - a[i] >= 2)
		{
			account = account + 1;
		}
	}
	cout << account << endl;
	return 0;
}

用了new

猜你喜欢

转载自blog.csdn.net/weixin_44003016/article/details/84886878