forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
9.5.cpp
32 lines (29 loc) · 747 Bytes
/
9.5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <vector>
#include <iostream>
#include <sstream>
std::vector<int>::const_iterator
hasValue(std::vector<int>::const_iterator begin,
std::vector<int>::const_iterator end,
int k) {
for (auto it = begin; it != end; ++it)
if (k == *it)
return it;
return end;
}
int main() {
std::string str;
std::getline(std::cin, str);
std::istringstream iss(str);
std::vector<int> vi;
int k;
while (iss >> k)
vi.push_back(k);
std::cin >> k;
auto it = hasValue(vi.cbegin(), vi.cend(), k);
if (it == vi.end())
std::cout << "No found " << k << " in range" << std::endl;
else
std::cout << "Found " << *it
<< " at position " << it - vi.cbegin() << std::endl;
return 0;
}