题解 | #序列重组矩阵#
序列重组矩阵
http://www.nowcoder.com/practice/7548f8f5e44c42fa84fb2323d899a966
思路 用静态变量,然后在循环中,实现累加换行判断,非常巧妙的思路 #include<stdio.h> int main(void) { int n = 0; //row int m = 0; //col
scanf("%d%d", &n, &m);
int kiki[n][m];
//enter datas
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &kiki[i][j]);
}
}
//output datas
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
static int line = 0;
printf("%d ", kiki[i][j]);
if (++line % m == 0) //m data per line
printf("\n");
} //end for j
} //end for i
return 0;
}