forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
5.17.cpp
33 lines (29 loc) · 749 Bytes
/
5.17.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
33
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
void readVector(std::vector<int> &v) {
std::string str;
std::getline(std::cin, str);
std::stringstream ss(str);
int i;
while(ss >> i)
v.push_back(i);
//for (const auto &e : v)
// std::cout << e << " ";
//std::cout << std::endl;
}
bool isPrefix(const std::vector<int> &v1, const std::vector<int> &v2) {
auto it1 = v1.cbegin(), it2 = v2.cbegin();
for (; it1 != v1.cend() && it2 != v2.cend(); ++it1, ++it2)
if (*it1 != *it2)
break;
return it1 == v1.cend() || it2 == v2.cend();
}
int main() {
std::vector<int> v1, v2;
readVector(v1);
readVector(v2);
std::cout << (isPrefix(v1, v2) ? "true" : "false") << std::endl;
return 0;
}