比较包含关系:
#include <iostream> #include<vector> #include<string> using namespace std; bool my(vector<int> a, vector<int> b, size_t size) { for (size_t i = 0; i < size; ++i) { if(a[i] != b[i]) return false; } return true; } int main() { vector<int> a,b; int c = 0; cout << "input a: "; while (cin >>c) a.push_back(c); cin.clear(); //cin.ignore(); cout << "input b: "; while (cin >> c) b.push_back(c); size_t size_a = a.size(), size_b = b.size(); size_t i = 0; bool re = size_a>size_b ? my(a,b,size_b):my(a,b,size_a); cout << boolalpha << re << endl; }