dev/cpp/bookAmmeraal/03/main.cpp

43 lines
920 B
C++

/* STL */
#include <algorithm>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
/* STD */
#include <iostream>
#include <string>
#include <cstdlib>
#include <math.h>
using namespace std;
// 1.5. Алгоритм find Найти заданное значение в векторе
int main (int argc, char *argv[]) {
vector<int> v;
int x;
cout << "Enter positive integers, followed by 0:\n";
while (cin >> x, x != 0)
v.push_back(x);
cout << "Value to be searched for: ";
cin >> x;
vector<int>::iterator i = find(v.begin(), v.end(), x);
if (i == v.end()) cout << "Not found\n";
else {
cout << "Found";
if (i == v.begin()) cout << " as the first element";
else cout << " after " << *--i;
}
cout << endl;
return 0;
}