计蒜客data structure:Code_01
package www.jisuanke.ds;
import java.util.ArrayList;
import java.util.Scanner;
/**
* @author wangchong
* @date 2019/4/30 16:09
* @email 876459397@qq.com
* @优快云 https://blog.youkuaiyun.com/wfcn_zyq
* @describe
*/
public class Code_01_SpecialMatrix {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
ArrayList[] arrayList = new ArrayList[n];
for (int i = 0; i < n; i++) {
arrayList[i] = new ArrayList<Integer>();
}
for (int i = 0; i < m; i++) {
int x = input.nextInt();
int y = input.nextInt();
arrayList[x - 1].add(y);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < arrayList[i].size(); j++) {
if (j < arrayList[i].size() - 1) {
System.out.print(arrayList[i].get(j) + " ");
} else {
System.out.print(arrayList[i].get(j));
}
}
System.out.println();
}
}
}
本文展示了一个使用Java实现的特殊矩阵处理算法。通过读取输入的矩阵尺寸和元素,程序构建并输出了特殊矩阵的结构。该算法利用ArrayList进行数据存储,实现了灵活的矩阵操作。
1万+

被折叠的 条评论
为什么被折叠?



