forked from Hawstein/cracking-the-coding-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.6.cpp
More file actions
28 lines (26 loc) · 593 Bytes
/
9.6.cpp
File metadata and controls
28 lines (26 loc) · 593 Bytes
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
#include <iostream>
#include <cstdio>
using namespace std;
int d[20][20];
int search(int m, int n, int x){
int r = 0, c = n-1;
while(r<m && c>=0){
if(d[r][c] == x) return (r * n + c);
else if(d[r][c] < x) ++r;
else --c;
}
return -1;
}
int main(){
freopen("9.6.in", "r", stdin);
int m, n;
cin>>m>>n;
for(int i=0; i<m; ++i)
for(int j=0; j<n; ++j)
cin>>d[i][j];
int k = search(m, n, 13);
if(k == -1) cout<<"not found"<<endl;
else cout<<"position: "<<k/n<<" "<<k%n<<endl;
fclose(stdin);
return 0;
}