#include<iostream>
#include<vector>
using namespace std;
cout << "please press into vec1's elements" << endl;
int a = 0;
bool flag1 = true;
while (flag1)
{
if (cin >> a) {
v1.push_back(a);
}
else {
flag1 = false;
cout << "vec1 is done" << endl;
}
}
cin.clear(); //清理状态
//cin.ignore(); //忽略最后输入的字符
cout << "please press into vec2's elements" << endl;
bool flag2 = true;
while (flag2)
{
if (cin >> a) {
v2.push_back(a);
}
else {
flag2 = false;
cout << "vec2 is done" << endl;
}
}
cout << "start comparing......" << endl;
vector<int> *vb = 0;
vector<int> *vs = 0;
if (v1.size() >= v2.size()) {
vb = &v1;
vs = &v2;
}
else {
vb = &v2;
vs = &v1;
}
bool flag = true;
for (vector<int>::iterator itr1 = (*vb).begin(), itr2 = (*vs).begin(); itr2 != (*vs).end(); ++itr1, ++itr2) {
if (*itr1 != *itr2) {
cout << "nnnnnnnnnnnnnnnnoooooooooo!"<<endl;
flag = false;
break;
}
}
if (flag) {
cout << "yes it is!" << endl;
}
else {
cout << "too bad" << endl;
}
return 0;
}
#include<vector>
using namespace std;
int main() {
vector<int> v1;
vector<int> v2;
cout << "please press into vec1's elements" << endl;
int a = 0;
bool flag1 = true;
while (flag1)
{
if (cin >> a) {
v1.push_back(a);
}
else {
flag1 = false;
cout << "vec1 is done" << endl;
}
}
cin.clear(); //清理状态
//cin.ignore(); //忽略最后输入的字符
cout << "please press into vec2's elements" << endl;
bool flag2 = true;
while (flag2)
{
if (cin >> a) {
v2.push_back(a);
}
else {
flag2 = false;
cout << "vec2 is done" << endl;
}
}
cout << "start comparing......" << endl;
vector<int> *vb = 0;
vector<int> *vs = 0;
if (v1.size() >= v2.size()) {
vb = &v1;
vs = &v2;
}
else {
vb = &v2;
vs = &v1;
}
bool flag = true;
for (vector<int>::iterator itr1 = (*vb).begin(), itr2 = (*vs).begin(); itr2 != (*vs).end(); ++itr1, ++itr2) {
if (*itr1 != *itr2) {
cout << "nnnnnnnnnnnnnnnnoooooooooo!"<<endl;
flag = false;
break;
}
}
if (flag) {
cout << "yes it is!" << endl;
}
else {
cout << "too bad" << endl;
}
return 0;
}