#include<iostream> using namespace std; void Print(int (*numbers)[4],int cols,int rows) { int t = cols > rows ? (rows+1) / 2 : (cols+1) / 2; int num = 0; while (num<t) { for (int i = num; i < cols-num-1; i++) { cout<<numbers[num][i]<<" "; } for (int j = num; j < rows - num - 1; j++) { cout << numbers[j][cols-1-num] << " "; } for (int p = cols-num-1; p > num; p--) { cout << numbers[rows-1-num][p] << " "; } for (int q = rows-num-1; q > num; q--) { cout << numbers[q][num] << " "; } num++; } } int main() { int a[3][4] = { {1,2,3,4},{5,6,7,8},{9,10,11,12} }; Print(a,4,3); return 0; }
剑指offer29
猜你喜欢
转载自blog.csdn.net/hikaru0123/article/details/80054757
今日推荐
周排行