-
Notifications
You must be signed in to change notification settings - Fork 0
/
SearchNumber.cpp
55 lines (53 loc) · 933 Bytes
/
SearchNumber.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <vector>
using namespace std;
bool SearchNumber(vector <vector<int> > &array,int number)
{
int j;
for(j = array[0].size()-1; j >= 0; j--)
{
if(array[0][j] == number)
{
return true;
}
else if(array[0][j] < number)
{
break;
}
}
if(j < 0)
{
return false;
}
for(size_t i = 0; i < array.size(); i++)
{
if(array[i][j] == number)
{
return true;
}
}
return false;
}
int main()
{
int arr[4][4]= { {1,2,8,9},{2,4,9,12},{4,7,10,13},{6,8,11,15} };
vector<vector<int> > array;
for(int i = 0; i< 4; i++)
{
vector<int > arr1;
for(int j = 0; j < 4; j++)
{
arr1.push_back(arr[i][j]);
}
array.push_back(arr1);
}
if(SearchNumber(array,12))
{
cout << " 找到了" << endl;
}
else
{
cout << "没有找到" << endl;
}
return 0;
}