kotlin 查找id_Kotlin程序查找矩陣的轉置

kotlin 查找id

A transpose of a matrix is simply a flipped version of the original matrix.
We can transpose a matrix by switching its rows with its columns

矩陣轉置只是原始矩陣的翻轉形式。
我們可以通過切換矩陣的行和列來轉置矩陣

Given a matrix, we have to find its transpose matrix.

給定一個矩陣,我們必須找到它的轉置矩陣。

Example:

例:

    Input:
matrix:
[2, 3, 4, 5, 6]
[7, 8, 9, 0, 9]
Output:
Transpose Matrix :
[2, 7]
[3, 8]
[4, 9]
[5, 0]
[6, 9]

在Kotlin中尋找矩陣轉置的程序 (Program to find transpose of a matrix in Kotlin)

package com.includehelp
import java.util.*
// Main function, Entry Point of Program
fun main(args: Array<String>) {
//variable of rows and col
val rows: Int
val column: Int
//Input Stream
val scanner = Scanner(System.`in`)
//Input no of rows and column
print("Enter the number of rows and columns of matrix : ")
rows   = scanner.nextInt()
column = scanner.nextInt()
//Create Array
val matrixA     = Array(rows) { IntArray(column) }
val transposeMatrix = Array(column) {IntArray(rows)}
//Input Matrix
println("Enter the Elements of First Matrix ($rows X $column} ): ")
for(i in matrixA.indices){
for(j in matrixA[i].indices){
print("matrixA[$i][$j]: ")
matrixA[i][j]=scanner.nextInt()
}
}
//print Matrix A
println("Matrix A : ")
for(i in matrixA.indices){
println("${matrixA[i].contentToString()} ")
}
//Transpose of Matrix
for(i in transposeMatrix.indices){
for(j in transposeMatrix[i].indices){
transposeMatrix[i][j]=matrixA[j][i]
}
}
//print Transpose Matrix
println("Transpose Matrix : ")
for(i in transposeMatrix.indices){
println("${transposeMatrix[i].contentToString()} ")
}
}

Output

輸出量

Run 1:
Enter the number of rows and columns of matrix : 3
4
Enter the Elements of First Matrix (3 X 4} ):
matrixA[0][0]: 2
matrixA[0][1]: 3
matrixA[0][2]: 4
matrixA[0][3]: 5
matrixA[1][0]: 6
matrixA[1][1]: 7
matrixA[1][2]: 8
matrixA[1][3]: 9
matrixA[2][0]: 0
matrixA[2][1]: 1
matrixA[2][2]: 2
matrixA[2][3]: 3
Matrix A :
[2, 3, 4, 5]
[6, 7, 8, 9]
[0, 1, 2, 3]
Transpose Matrix :
[2, 6, 0]
[3, 7, 1]
[4, 8, 2]
[5, 9, 3]
----
Run 2:
Enter the number of rows and columns of matrix : 2
5
Enter the Elements of First Matrix (2 X 5} ):
matrixA[0][0]: 2
matrixA[0][1]: 3
matrixA[0][2]: 4
matrixA[0][3]: 5
matrixA[0][4]: 6
matrixA[1][0]: 7
matrixA[1][1]: 8
matrixA[1][2]: 9
matrixA[1][3]: 0
matrixA[1][4]: 9
Matrix A :
[2, 3, 4, 5, 6]
[7, 8, 9, 0, 9]
Transpose Matrix :
[2, 7]
[3, 8]
[4, 9]
[5, 0]
[6, 9]

翻譯自: https://www.includehelp.com/kotlin/find-transpose-of-a-matrix.aspx

kotlin 查找id

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377967.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377967.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377967.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

[mongodb翻譯]分片和故障轉移

一個配置恰當的mongodb 分片集群不會有單點失效。 本章節描述了集群服務器中可能出現的故障&#xff0c;及相應的對策。 1. 某個mongos路由進程故障 每一個mongos會運行每一臺應用服務器上面&#xff0c;該應用服務器只能通過這個mongos進程和集群進行通信。mongos進程不是…

看張子陽的書真是收獲很多,也醒悟了很多(一)

摘錄&#xff1a; 這是有一次開會時&#xff0c;我的老總跟我們說了這樣一個事例&#xff1a;通常來說&#xff0c;醫生是很高尚的職業&#xff08;暫不考慮國內醫生的負面新聞&#xff09;&#xff0c;尤其是牙科醫生&#xff0c; 他們有著體面的工作并且收入不菲。但是&#…

【C++ grammar】抽象、封裝與this指針

目錄1、Abstraction and Encapsulation&#xff08;抽象與封裝&#xff09;1. Data Field Encapsulation (數據域封裝)2. Accessor and Mutator (訪問器與更改器)2.1. To read/write private data, we need get/set function (為讀寫私有數據&#xff0c;需要get/set函數)2.2. …

java創建臨時文件_用Java創建一個臨時文件

java創建臨時文件The task is to create a temporary file in Java. 任務是用Java創建一個臨時文件。 Creating a temporary file 創建一個臨時文件 To create a temporary file in java – we use createTempFile() method of "File" class. The createTempFile()…

十九、圖像的形態學操作

一、圖像形態學 圖像形態學是圖像處理學科的一個單獨分支學科 主要針對的是灰度圖和二值圖像 是由數學的集合論以及數學中的拓撲幾何原理發展而來 二、膨脹操作&#xff08;dilate&#xff09; 33的卷積核 以33為卷積核從左往右(從上往下)開始運行&#xff0c;若這卷積核…

X名稱空間(WPF)

筆記簡述 閑話x名稱空間簡要x名稱空間的Attributex名稱空間的標簽擴展x名稱空間的XAML指令元素閑話 本筆記參考與《深入淺出WPF》、MSDN、Some Blog… MSDN的飛機票點這里。 x名稱空間簡要 在VS中新建個WpfApplication都會自動生成xmlns:x"http://schemas.microsoft.com/w…

基于Bresenham和DDA算法畫線段

直線&#xff1a;ykxb 為了將他在顯示屏上顯示出來&#xff0c;我們需要為相應的點賦值&#xff0c;那么考慮到計算機的乘法執行效率&#xff0c;我們肯定不會選擇用Ykxb這個表達式求值&#xff0c;然后進行畫線段。 我們應當是將它轉化為加法運算。 下面提供兩種常見的算法&am…

leetcode 106. 從中序與后序遍歷序列構造二叉樹 105. 從前序與中序遍歷序列構造二叉樹思考分析

目錄1、106題目2、參考思路&#xff1a;遞歸切割數組3、105題目4、同樣思路的代碼1、106題目 2、參考思路&#xff1a;遞歸切割數組 代碼參考&#xff1a;公眾號&#xff1a;代碼隨想錄 后序數組中序數組 以 后序數組(左右中)的最后一個元素作為切割點&#xff0c;先切中序數組…

按頻率對元素進行排序

Prerequisite: 先決條件&#xff1a; Hashing data structure 散列數據結構 How to write user-defined comparator for priority queue STL in C? 如何在C 中為優先級隊列STL編寫用戶定義的比較器&#xff1f; How to sort a map based on values instead of value? 如何根…

二十、分水嶺算法

一、基本原理 分水嶺算法主要是基于距離變換&#xff08;distance transform&#xff09;&#xff0c;找到mark一些種子點&#xff0c;從這些種子點出發根據像素梯度變化進行尋找邊緣并標記 分水嶺&#xff1a;可以簡單的理解成一座山&#xff0c;然后來洪水了&#xff0c;水開…

細數WOW里暴雪的“親兒子”們

. 不知何時&#xff0c;魔獸世界的詞匯中忽然出現了一個新玩意&#xff1a;親兒子。雖說這個稱呼現在大多是拿來調侃法爺的&#xff0c;但江山代有兒子出&#xff0c;各領風騷一兩天&#xff0c;今天風光無限的法爺們也經歷過被其他職業壓得抬不起頭的小媳婦生涯。那么今天…

Linux下串口ttyS2,ttyS3不能用的問題解決辦法

PC104&#xff0c;Xlinux下&#xff0c;突然發現串口3,4不能用。。。 以為是硬件的問題&#xff0c;換成wince后&#xff0c;3,4工作正常&#xff0c;排除電路問題 在linux下查看dmesg: serial8250: ttyS0 at I/O 0x3f8 (irq 4) is a 16550Aserial8250: ttyS1 at I/O 0x2f8 (i…

安卓log.e函數打印示例_log1p()函數以及C ++中的示例

安卓log.e函數打印示例C log1p()函數 (C log1p() function) log1p() function is a library function of cmath header, it is used to get the natural logarithm (the base-e logarithm) of the one plus given value. It accepts a value (float, double, or long double) …

【C++grammar】C++類數據成員的初始化

目錄1、類成員的就地初始化example2、構造函數初始化3、默認構造函數&#xff1a;Default Constructor4、舉例5、成員的初始化方法的優先級1、類成員的就地初始化example class S { int m 7; // ok, copy-initializes m int n(7); // 錯誤&#xff1a;不允許用小括號初始化…

二十一、人臉檢測

一、識別圖像中的人臉 haarcascade_frontalface_alt_tree.xml lbpcascade_frontalcatface.xml GitHub上有Haar級聯檢測器源代碼可自行下載&#xff0c;lbp級聯檢測器也一樣有源碼可自行下載 也一樣 import cv2 as cv import numpy as npdef face_detect(image):gray cv.cvtC…

aspx特殊符號說明

http://www.cnblogs.com/GnagWang/archive/2010/07/14/1777130.html轉載于:https://www.cnblogs.com/mingyongcheng/archive/2011/11/24/2261253.html

javascript運算符_JavaScript中的按位運算符

javascript運算符JavaScript按位運算符 (JavaScript Bitwise Operators) A lot of times you come across some strange operators where youre knocking your head to understand what is going on in the code. Almost all the programming languages have bitwise operators…

[置頂] Android的IPC訪問控制設計與實現

3.3.1 IPC鉤子函數設計與實現 IPC Binder是Android最重要的進程間通信機制&#xff0c;因此&#xff0c;必須在此實施強制訪問控制。 1. 修改secuirty.h 打開終端shell&#xff0c;輸入指令“cd /android4.0/kernel/goldfish/include/linux/vim security.h”&#xff0c;找到結…

TensorFlow在Anaconda環境下創建

一、我使用的是Anaconda自帶的Jupyter編譯器&#xff0c;詳細的安裝教程可以參考博文 二、之后打開Jupyter 三、進行測試 我的tensorflow使用的是2.0版本 import tensorflow.compat.v1 as tf tf.disable_v2_behavior()a tf.constant([1.0,2.0],name"a") b tf.co…

leetcode 654. 構造最大二叉樹 思考分析

題目 給定一個不含重復元素的整數數組。一個以此數組構建的最大二叉樹定義如下&#xff1a; 二叉樹的根是數組中的最大元素。 左子樹是通過數組中最大值左邊部分構造出的最大二叉樹。 右子樹是通過數組中最大值右邊部分構造出的最大二叉樹。 通過給定的數組構建最大二叉樹&am…