1 条题解

  • 0
    @ 2023-6-11 12:16:47

    C :

    #include<stdio.h>
    int main()
    {
    	int n,m;
    	scanf("%d %d",&n,&m);
    	int i,j,a[n][m];
    	for(i=0;i<n;i++){
    		for(j=0;j<m;j++){
    			scanf("%d",&a[i][j]);
    		}
    	}
    	for(i=1;i<n-1;i++){
    		for(j=1;j<m-1;j++){
    			if(a[i][j]>a[i-1][j]&&a[i][j]>a[i][j-1]&&a[i][j]>a[i][j+1]&&a[i][j]>a[i+1][j]){
    				printf("%d\n",a[i][j]);
    			} 
    		} 
    	}
    	return 0;
    }
    

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
    	int i,n,m,j;
    	int a[110][110];
    	cin>>n>>m;
    	for(i=0;i<n;i++){
    		for(j=0;j<m;j++){
    			cin>>a[i][j];
    		}
    	}
    	for(i=1;i<n-1;i++){
    		for(j=1;j<m-1;j++){
    			if(a[i][j]>a[i-1][j]&&a[i][j]>a[i+1][j]&&a[i][j]>a[i][j-1]&&a[i][j]>a[i][j+1]){
    				cout<<a[i][j]<<endl;
    			}
    		}
    	}
    	
    }
    

    Python :

    n,m=list(map(int,input().split()))
    a=list()
    for i in range(n):
        a.append(list(map(int,input().split())))
    
    
    
    for i in range(1,n-1):
        for j in range(1,n-1):
            if(a[i][j]>a[i-1][j] and a[i][j]>a[i][j+1] and a[i][j]>a[i+1][j] and a[i][j]>a[i][j-1]):
                print(a[i][j])
            
    
    
    • 1

    信息

    ID
    2304
    时间
    1000ms
    内存
    16MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者