爱奇艺的测试工程师笔试题
题目:
解答:
#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; }
新战场:https://blog.csdn.net/Stephen___Qin