本文主要是介绍vj467A--George and Accommodation,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题来源
vj467A
问题描述
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.
输入
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.
输出
Print a single integer — the number of rooms where George and Alex can move in.
例子
AC的代码
#include<iostream>
using namespace std;
int main()
{int i,t,k,s=0;cin>>i;while(i){cin>>t;cin>>k;if((k-t)>=2)s++;i--;}
cout<<s;}
解题思路
用i保存示例数,i次循环分别输入已有人数和可住人数,若有一个房间可住人数减去已有人数大于等于2,则s加一,循环结束输出s,则为可住房间数。
这篇关于vj467A--George and Accommodation的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!