-3
我有一个deque<int>
我想找到两个相等的数字之间的数量是否为偶数。例如:7,13,4,6,4,13,8,10
应该是false,1,3,5,3,4,8,7,9,6,5,7
应该是true。我认为我的程序是正确的,但是或者是因为两种情况都是正确的。任何想法为什么? PS:我对迭代器不太好。看看两个相等的数字之间的长度是双数是甚至
#include <iostream>
#include <deque>
using namespace std;
bool isJoined (deque<int>::iterator begin, deque<int>::iterator end)
{
for(auto i = begin ; i < end ;i++)
for(auto j=i+1;j<end;j++)
if(*i == *j && (j-i)%2 == 0)
return true;
return false;
}
int main()
{
deque<int> test = {1,3,5,3,4,8,7,9,6,5,7};
deque<int> test2 = {7,13,4,6,4,13,8,10};
cout<<isJoined(test.begin(),test.end())<<endl;
cout<<isJoined(test2.begin(),test2.end())<<endl;
}
您可以acc ess deques用[]'表示 – Brian
之间任何两个相等? 2 1 2 3 4 5 3的答案是什么? – sashas
@migdal答案是对的。两个'3'之间。 – pesho