爱奇艺的测试工程师笔试题

题目:

解答:

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int nNum,nArrayElement;
    vector<int> vecArray;
    cin >> nNum;
    for (int i = 0; i < nNum; i++)
    {
        cin >> nArrayElement;
        vecArray.push_back(nArrayElement);
    }
    int nNumofInterval = 1;
    for (int i = 0; i < nNum-1; i++)
    {
        //如果前后相差不等于1,则自增
        if (vecArray[i+1] - vecArray[i] != 1)
        {
            nNumofInterval++;
        }
    }
    cout << nNumofInterval;
    return 0;
}

 

posted @ 2017-10-28 21:57  心媛意码  阅读(1034)  评论(0编辑  收藏  举报