zoukankan      html  css  js  c++  java
  • 数据结构实验之数组一:矩阵转置(SDUT 2130)

    Problem Description

    数组——矩阵的转置

    给定一个m*n的矩阵(m,n<=100),求该矩阵的转置矩阵并输出。


    Input

     输入包含多组测试数据,每组测试数据格式如下:

    第一行包含两个数m,n

    以下m行,每行n个数,分别代表矩阵内的元素。

    (保证矩阵内的数字在int范围之内)


    Output

     对于每组输出,输出给定矩阵的转置矩阵。两组输出之间用空行隔开。


    Sample Input

    2 3
    1 2 3
    4 5 6
    1 1
    1
    

    Sample Output

    1 4
    2 5
    3 6
    
    1

    解析:比较懒就直接输出了,好像标准做法不是酱紫的。

    #include <stdio.h>
    #include <string.h>
    int a[105][105];
    int main()
    {
        int n, m;
        while(~scanf("%d %d", &n, &m))
        {
            for(int i = 0; i < n; i ++)
            {
                for(int j = 0; j < m; j ++)
                {
                    scanf("%d", &a[i][j]);
                }
            }
            for(int i = 0; i < m; i ++)
            {
                for(int j = 0; j < n; j ++)
                {
                    if(j == 0) printf("%d",a[j][i]);
                    else printf(" %d",a[j][i]);
                }
                printf("
    ");
            }
            printf("
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    h5 canvas
    css3选择器
    弹性盒模型
    css新增属性
    蒙版 倒影 渐变
    字符串转化为json的三种方法
    Final互评------《弹球学成语》---- 杨老师粉丝群
    Final互评------《飞词》---- 拉格朗日2018
    作业 20181204-4 互评Final版本
    换手
  • 原文地址:https://www.cnblogs.com/lcchy/p/10139635.html
Copyright © 2011-2022 走看看