第四周作业——图的表示
来源:互联网 发布:江苏省数据统计局 编辑:程序博客网 时间:2024/06/11 04:00
import java.util.ArrayList; import java.util.List; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.Reader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.FileWriter; public class GraphRepresentation { public static void main(String[] orgs){ Test3 test3=new Test3(); test3.test("D:\\tinyG.txt"); } } class Test3{ Test3(){} void test(String PathName){ FileReader file1 = null; try { file1 = new FileReader(PathName); } catch (FileNotFoundException e) { e.printStackTrace(); } BufferedReader br=new BufferedReader(file1); String s1=null; int line=0; String [][]strs=new String[13][2]; int count=0; try { while((s1=br.readLine())!=null){ line++; if(line==1||line==2||line==3)continue; String str=s1.trim(); if(!str.isEmpty()){ strs[count]=str.split(" "); count++; } } } catch (IOException e) { e.printStackTrace(); } int[][] s5=new int [13][13]; for(int i=0;i<12;i++){ for(int j=0;j<12;j++){ s5[i][j]=0; } } for(int i=0;i<13;i++){ for(int j=0;j<2;j++){ s5[Integer.parseInt(strs[i][0])][Integer.parseInt(strs[i][1])]=1; s5[Integer.parseInt(strs[i][1])][Integer.parseInt(strs[i][0])]=1; } } File file = new File("D:\\array.txt"); //存放数组数据的文件 FileWriter out = null; try { out = new FileWriter(file); } catch (IOException e) { e.printStackTrace(); } //文件写入流 //将数组中的数据写入到文件中。每行各数据之间TAB间隔 for(int i=0;i<12;i++){ for(int j=0;j<12;j++){ try { out.write(s5[i][j]+" "); } catch (IOException e) { e.printStackTrace(); } } try { out.write("rn"); } catch (IOException e) { e.printStackTrace(); } } try { out.close(); } catch (IOException e) { e.printStackTrace(); } } }
0 0
- 第四周作业—图的表示
- 第四周作业—图的表示
- 第四周作业—图的表示
- 第四周作业—图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示(GraphRepresentation)
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- C#修改系统时间
- LeetCode: Path Sum II [113]
- UVa 10340 - All in All
- Eclipse java swing开发环境
- LeetCode: Flatten Binary Tree to Linked List [114]
- 第四周作业——图的表示
- 《Essential C++》随笔一
- vba中的正则表达式
- Java 结束线程方式
- JAVA判断字符是中文,数字,etc
- LeetCode: Distinct Subsequences [115]
- Test Test
- CSS属性,盒子模型以及浮动和定位技术相关
- 使用泛型实现栈结构