我试试!
//------------------------------------------------------------------------------------
//
解答:怎么找出一个一维数组中有几个对子?
//
比如说:a[ ] ={1,2,2,3,3,4,2}
//
---zzy
//
2008.5.30
//-----------------------------------------------------------------------------------
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout<<"Please input data of int and finished by any characters:"<<endl;
vector<int> ivec;
int temp;
while(cin>>temp)
ivec.push_back(temp);
int i=0,count=0;
int n=ivec.size();
vector<int>::iterator iter=ivec.begin();
while(i<n)
{
for(int j=i+1;j<n;++j)
{
if(iter[j]!=iter[i])
break;
}
if((j-i)>1)
count+=1;
i=j;
}
cout<<"The number of pair of the vector:"<<count<<endl;
return 0;
}