23.11.13

题目:

image

代码:

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
#include <iostream>
using namespace std;
bool aaaa(int a[][4],int x,int y,int num){
int i=0;//行
int j=y-1;//列
while(i<=x-1&&j>=0){
if(a[i][j]==num){
return true;
}else if(a[i][j]>num){//放弃列
j--;
}else{//放弃行
i++;
}
}
return false;
}
int main(){
int a[4][4]={1,2,8,9,
2,4,9,12,
4,7,10,13,
6,8,11,15};
int num;
while(cin>>num){
if(aaaa(a,4,4,num)){
cout<<"true"<<endl;
}else{
cout<<"false"<<endl;
}
}
return 0;
}

运行结果:

image