数据结构实验之数组一:矩阵转置
Time Limit: 1000MS Memory Limit: 65536KB
ProblemDescription
数组——矩阵的转置
给定一个m*n的矩阵(m,n<=100),求该矩阵的转置矩阵并输出。
Input
输入包含多组测试数据,每组测试数据格式如下:
第一行包含两个数m,n
以下m行,每行n个数,分别代表矩阵内的元素。
(保证矩阵内的数字在int范围之内)
Output
对于每组输出,输出给定矩阵的转置矩阵。两组输出之间用空行隔开。
ExampleInput
2 3   1 2 3   4 5 6   1 1   1  ExampleOutput
1 4   2 5   3 6       1  Hint
Author
赵利强
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    while(~scanf("%d%d",&m,&n))
    {
       int i,j;
       int a[101][101];
       for(i = 1;i<=m;i++)
       for(j=1;j<=n;j++)
       scanf("%d",&a[i][j]);
       for(i=1;i<=n;i++)
       {
        for(j=1;j<m;j++)
        {
          printf("%d ",a[j][i]);
        }
        printf("%d\n",a[j][i]);
       }
       printf("\n");
    }
    return 0;
}
/***************************************************
User name: jk160505徐红博
Result: Accepted
Take time: 8ms
Take Memory: 188KB
Submit time: 2017-02-10 19:15:25
****************************************************/
  
  

京公网安备 11010502036488号