AOJ - Problem 2185 : Petting Cats

(X,Y)の位置に縦H横Wの建物があり、n匹の猫の座標が与えられたときに建物の中にいる猫の数を求める問題です。大小の比較で(x,y)にいる猫がその矩形(建物)のなかに含まれているか調べられます。

#include <iostream>
using namespace std;

int main(){
	int t;
	cin >> t;
	for(int i=0 ; i < t ; i++ ){
		int X, Y, W, H, n, ans=0;
		cin >> X >> Y >> W >> H >> n;
		for(int j=0 ; j < n ; j++ ){
			int x,y;
			cin >> x >> y;
			if( X <= x && x <= X+W && Y <= y && y <= Y+H ){
				ans++;
			}
		}
		cout << ans << endl;
	}
}