我的代码:
#include <bits/stdc++.h>
using namespace std;
int a[15][15];
int main(){
int n,start=1,end,cnt=0;
cin>>n;
end=n;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j];
while(cnt<=n*n){
for(int j=start;j<=end;j++){
cout<<a[start][j]<<' ';
cnt++;
}
for(int i=start+1;i<=end;i++){
cout<<a[i][end]<<' ';
cnt++;
}
for(int j=end-1;j>=start;j--){
cout<<a[end][j]<<' ';
cnt++;
}
for(int i=end-1;i>=start-1;i--){
cout<<a[i][start]<<' ';
cnt++;
}
start++;
end--;
}
return 0;
}
}
