chapter11-1.cpp

来自「大量程序实例」· C++ 代码 · 共 23 行

CPP
23
字号
//文件名:CHAPTER11-1.cpp
#include <algorithm>
#include <iostream>
using namespace std;
void main()
{
    const int ARRAY_SIZE = 8 ;
    int IntArray[ARRAY_SIZE] = { 1, 2, 3, 4, 4, 5, 6, 7 } ;
    int *location ;   // stores the position for the first pair of matching consecutive elements.
    int i ;
    // print content of IntArray
    cout << "IntArray { " ;
    for(i = 0; i < ARRAY_SIZE; i++)
        cout << IntArray[i] << ", " ;
    cout << " }" << endl ;
    location = adjacent_find(IntArray, IntArray + ARRAY_SIZE) ;
    //print the matching consecutive elements if any were found
    if (location != IntArray + ARRAY_SIZE)  // matching consecutive elements found
        cout << "Found adjacent pair of matching elements: (" << *location << "," << *(location + 1) << "), " <<"at location " << location - IntArray << endl;
    else         // no matching consecutive elements were found
        cout << "No adjacent pair of matching elements were found"<< endl ;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?