第一次编程练习第二题

编程练习第二题

网址 https://vjudge.net/problem/CodeForces-467A

题目: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.

    #include<iostream>
    #include<string>
    using namespace std;
    int main()
    {
    	int a, n, c = 0;
    	int b[1000];
    	cin >> n;
    	for (; n != c / 2; c += 2)
    	{
    		scanf("%d %d", &b[c], &b[c + 1]);
    	}
    	for (c = 0, a = 0; n != c/2; c += 2)
    	{
    		if (b[c + 1] - b[c] >= 2)
    			a++;
    	}
    	cout << a;
    	return 0;
    }

很简单的一题,唯一要注意的是输入的格式用scanf比较容易解决

猜你喜欢

转载自blog.csdn.net/weixin_43508349/article/details/84845228