题解 | #序列重组矩阵#
序列重组矩阵
http://www.nowcoder.com/practice/7548f8f5e44c42fa84fb2323d899a966
python:
n,m=map(int, input().split(" "))
a=[]
a=list(input().split(" "))
for i in range(n*m):
print(a[i],end='')
print(' ',end='')
if (i+1)%m==0:
print()
C语言: c其实不用嵌套直接到m的倍数换行即可
#include<stdio.h>
int main(){
int n,m,i;
scanf("%d %d",&n,&m);
int a[n*m];
for(i=0;i<n*m;i++){
scanf("%d",&a[i]);
}
for(i=0;i<n*m;i++){
printf("%d ",a[i]);
if((i+1)%m==0){//到一行最后就换行
printf("\n");
}
}
}