acm2

实验思路:
定义int 类型n,p,q,o.以n来储存房间数量,p来储存房间已住人数,q来储存房间容量,o为符合要求的房间数。首先输入房间数,然后用for循环来实现对q和p的输入,若满足条件,o则加1,直到n为0时,退出循环。然后输出符合要求的房间数。

#include<iostream>
using namespace std;
int main()
{
	int n, p, q, o = 0;
	cin >> n;
	for ( ;n>0;n--)
	{
		cin >> p;
		cin >> q;
		if ((q - p) >= 2)
		{
			o++;
		}
	}
	cout << o;
		
	
}

猜你喜欢

转载自blog.csdn.net/weixin_43974422/article/details/84863723
ACM