蓝桥杯基础的联系 回形取数

    技术2024-04-20  106

    算法上有规律可寻,具体规律看如下代码(语言表述不太流利)

    #include<stdio.h> //输入第一行是两个不超过200的正整数m, n, //表示矩阵的行和列 int main() { int m,n,a[200][200]={0},i,j,count1=0,count2=0,k,p; scanf("%d %d",&m,&n); for(i=0;i<m;i++) { for(j=0;j<n;j++) { scanf("%d",&a[i][j]); } } //取数 while(count2!=m*n) {

    for(i=count1;i<m-count1;i++) { printf("%d ",a[i][count1]); ++count2; if(count2==n*m) goto end; } i=i-1; // printf("%d-",i); for(j=count1+1;j<n-count1;j++) { printf("%d ",a[i][j]); ++count2; if(count2==n*m) goto end; } j=j-1; // printf("%d-",j); for(k=m-2-count1;k>=count1;k--) { printf("%d ",a[k][j]); ++count2; if(count2==n*m) goto end; } k=k+1; // printf("%d-",k); ++count1; for(p=n-1-count1;p>=count1;p--) { printf("%d ",a[k][p]); ++count2; if(count2==n*m) goto end; } if(count2==n*m) break; } end:; return 0;

    }

    Processed: 0.016, SQL: 9