标签:title 水题 code for pre ram upload continue tle
给定一个row行col列的整数数组array,要求从array[0][0]元素开始,按从左上到右下的对角线顺序遍历整个数组。
3 4 1 2 4 7 3 5 8 10 6 9 11 12
1 2 3 4 5 6 7 8 9 10 11 12
1 /*2016年12月3日openjudge日常水题 2 ————1.8.21 By Lxzy_Zby*/ 3 #include<cstdio> 4 using namespace std; 5 int main() 6 { 7 int row,col,k=0; 8 scanf("%d%d",&row,&col); 9 int a[row][col]; 10 for(int i=0;i<row;i++) 11 for(int j=0;j<col;j++) 12 scanf("%d",&a[i][j]); 13 int s=0,l=0,shu=0; 14 while(1) 15 { 16 int s1=s,l1=l; 17 while(1) 18 { 19 printf("%d\n",a[s1][l1]); 20 if(s1+1<row&&l1-1>=0) 21 { 22 s1++; 23 l1--; 24 shu++; 25 } 26 else 27 break; 28 } 29 if(l<col-1) 30 { 31 l++; 32 continue; 33 } 34 if(l==col-1&&s<row-1) 35 { 36 s++; 37 continue; 38 } 39 if(l==col-1&&s==row-1) 40 break; 41 42 } 43 return 0; 44 }
标签:title 水题 code for pre ram upload continue tle
原文地址:http://www.cnblogs.com/zby-ccsygz/p/6129970.html