day1 转置矩阵

这篇博客介绍了如何使用Java实现矩阵的转置操作。通过解释矩阵转置的概念,即交换矩阵的行和列,博主分享了第一次刷题的经历,包括在理解和编码过程中遇到的挑战,如返回语句错误和对输入输出的理解误区。博主表达了坚持学习的决心。
摘要由CSDN通过智能技术生成

题目:
给你一个二维整数数组 matrix, 返回 matrix 的 转置矩阵 。
矩阵的 转置 是指将矩阵的主对角线翻转,交换矩阵的行索引与列索引。
在这里插入图片描述
题解:

class Solution(){
   
	public int[][] transpose(int[][
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Map.put(keyword, accountList); keywordJList.setListData(keywordList.toArray(new String[0])); } accountList.add(account); textArea.append(account.toString() + "\n"); idTextField.setText(""); typeTextField.setText(""); costTextField.setText(""); 在 C 语言中,可以使用二维数组来表示方阵。方阵转置的具体实现可以使用两 keywordTextField.setText(""); } else { JOptionPane.showMessageDialog(this, "Invalid account information."); } }); saveButton.addActionListener(event -> { int result = fileChooser.showSaveDialog(this); if (result == JFileChooser.APPROVE_OPTION) { data重循环遍历原数组,然后将原数组的第 $i$ 行第 $j$ 列的元素赋值File = fileChooser.getSelectedFile(); try { BufferedWriter writer = new BufferedWriter(new FileWriter(dataFile)); for (Map.Entry<String,给转置数组的第 $j$ 行第 $i$ 列的元素。 以下是一个示例代码: ```c ArrayList<Account>> entry : accountMap.entrySet()) { String keyword = entry.getKey(); ArrayList<Account> accountList = entry.getValue(); #include <stdio.h> #define N 3 void transpose(int mat[][N], int transposed[][N]) { int i, j writer.write(keyword + "\n"); for (Account account : accountList) { writer.write(account.toString() + "\n"); ; for (i = 0; i < N; i++) { for (j = 0; j < N; j } } writer.close(); } catch (IOException e) { JOptionPane.showMessageDialog(this, "Failed to save data file."); ++) { transposed[j][i] = mat[i][j]; } } } int main() { int mat[N][ } } }); loadButton.addActionListener(event -> { int result = fileChooser.showOpenDialog(this); if (result ==N] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9 JFileChooser.APPROVE_OPTION) { dataFile = fileChooser.getSelectedFile(); try { BufferedReader reader = new BufferedReader(new FileReader}}; int transposed[N][N]; transpose(mat, transposed); int i, j; printf("Original matrix:\n(dataFile)); String line; while ((line = reader.readLine()) != null) { String keyword = line; ArrayList<Account"); for (i = 0; i < N; i++) { for (j = 0; j < N; j> accountList = new ArrayList<Account>(); while ((line = reader.readLine()) != null && !line.isEmpty()) { Account account = new Account(line); accountList.add(account); } accountMap.put(keyword, accountList); if (!keywordList.contains(keyword++) { printf("%d ", mat[i][j]); } printf("\n"); } printf("Transposed matrix:\n)) { keywordList.add(keyword); } } reader.close(); keywordJList.setListData(keywordList.toArray(new String"); for (i = 0; i < N; i++) { for (j = 0; j < N; j[0])); } catch (IOException e) { JOptionPane.showMessageDialog(this, "Failed to load data file."); } } ++) { printf("%d ", transposed[i][j]); } printf("\n"); } return 0; } `` }); } /** * 更新日历面板 */ private void updateCalendarPanel() { calendar.setTime(currentDate); calendar.set(Calendar.DAY_OF_MONTH, 1); int firstDayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); int days` 这里的 `mat` 表示原方阵,`transposed` 是转置后的方阵,都是二维OfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); calendarPanel.removeAll(); String[] daysOfWeek = { "Sun", "Mon数组。在 `main` 函数中,先输出原方阵,然后调用 `transpose` 函数进行转置,最后", "Tue", "Wed", "Thu", "Fri", "Sat" }; for (String dayOfWeek : daysOfWeek) { calendarPanel.add(new JLabel(dayOfWeek, JLabel.CENTER)); } for (int i = 1; i < firstDayOfWeek; i输出转置后的方阵。可以看到,转置后的方阵矩阵的行列与原矩阵相反。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值