解题思路:
注意事项:
参考代码:
#include<iostream> using namespace std; const int M=200+5; int a[M][M]={0}; int main() { int m,n; while(cin>>m>>n) { for(int i=0;i<m;i++) { for(int j=0;j<n;j++) { cin>>a[i][j]; } } int x=0,y=0; cout<<a[x][y]; a[x][y]=-1; int t=m*n-1; while(t>0) { while(x+1<m&&a[x+1][y]!=-1) { cout<<' '<<a[++x][y]; a[x][y]=-1; t--; } while(y+1<n&&a[x][y+1]!=-1) { cout<<' '<<a[x][++y]; a[x][y]=-1; t--; } while(x-1>=0&&a[x-1][y]!=-1) { cout<<' '<<a[--x][y]; a[x][y]=-1; t--; } while(y-1>=0&&a[x][y-1]!=-1) { cout<<' '<<a[x][--y]; a[x][y]=-1; t--; } } cout<<endl; } return 0; }
0.0分
0 人评分
DNA (C++代码)浏览:652 |
十->二进制转换 (C++代码)(零和负数需要特殊处理)浏览:1052 |
数列 (C++代码)浏览:671 |
简单的a+b (C语言代码)浏览:555 |
IP判断 (C语言代码)浏览:783 |
【蟠桃记】 (C语言代码)浏览:1045 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:566 |
A+B for Input-Output Practice (V) (C语言代码)浏览:471 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:708 |
C二级辅导-同因查找 (C语言代码)浏览:573 |