![]() |
#2
bczger2014-03-13 23:35
|
这是原题目。我改进了下:自己输入vector的元素,回车结束输出。然后自己输入要找的数字。
结果不对,应该输入vector元素的时候错了吧。

#include <iostream>
#include <vector>
using namespace std;
bool find(vector<int>::iterator first,vector<int>::iterator last,int x)
{
while(first!=last)
{
if(*first==x)
return 1;
first++;last++;
}
return 0;
}
void main()
{
vector<int> vec;
int ival;
while(cin >> ival)
{
if(ival==(int)('\n'))
break;
vec.push_back(ival);
}
cout << "input the figure you want to find" << endl;
int x;
cin >> x;
vector<int>::iterator fir = vec.begin();
vector<int>::iterator las = vec.end();
bool fin;
fin=find(fir,las,x);
if(fin)
cout << "yes ,there is" << endl;
else
cout << "no,there isn't" << endl;
}
#include <vector>
using namespace std;
bool find(vector<int>::iterator first,vector<int>::iterator last,int x)
{
while(first!=last)
{
if(*first==x)
return 1;
first++;last++;
}
return 0;
}
void main()
{
vector<int> vec;
int ival;
while(cin >> ival)
{
if(ival==(int)('\n'))
break;
vec.push_back(ival);
}
cout << "input the figure you want to find" << endl;
int x;
cin >> x;
vector<int>::iterator fir = vec.begin();
vector<int>::iterator las = vec.end();
bool fin;
fin=find(fir,las,x);
if(fin)
cout << "yes ,there is" << endl;
else
cout << "no,there isn't" << endl;
}