A. George and Accommodation
Solution With C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int p,q;
int count;
for(int i=0; i<n; i++)
{
cin>>p>>q;
if(q-p>1)
count++;
}
cout<<count;
}
A. George and Accommodation
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.
George和住宿
每次测试的时间限制1秒
每个测试的内存限制256 MB 输入标准输入 输出标准输出George 最近进入了 BSUCP(Berland State University for Cool Programmers)。 乔治有一个朋友亚历克斯,他也进入了大学。 现在他们搬进了宿舍。 乔治和亚历克斯想住在同一个房间里。 宿舍共有n个房间。 目前第i个房间有pi人居住,房间总共可以容纳qi人(pi ≤ qi)。 你的任务是计算乔治和亚历克斯有多少房间有空位。 输入 第一行包含一个整数 n (1 ≤ n ≤ 100)——房间的数量。 接下来 n 行的第 i 行包含两个整数 pi 和 qi (0 ≤ pi ≤ qi ≤ 100)——已经住在第 i 个房间的人数和房间的容量。
输出 打印一个整数——乔治和亚历克斯可以入住的房间数量。
3
1 1
2 2
3 3
0
3
1 10
0 10
10 10
2
Solution With C++
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int p,q;
int count;
for(int i=0; i<n; i++)
{
cin>>p>>q;
if(q-p>1)
count++;
}
cout<<count;
Comments
Post a Comment