第四周作业——图的表示
来源:互联网 发布:js粒子运动轨迹 编辑:程序博客网 时间:2024/05/16 15:15
package work;import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.OutputStreamWriter; public class GraphRepresentation { public static void main(String[] args) { try { FileReader r=new FileReader("F:/Arithmetic/tinyG.txt"); BufferedReader o=new BufferedReader(r); int tc; String str=""; str=o.readLine(); int a=Integer.parseInt(str); str=o.readLine(); int E=Integer.parseInt(str); int[][] arry=new int[a][a]; str=""; int v=0,e=0; while((tc=o.read())!=-1) { str=str+(char)tc; if ((char)tc==' ') { v=Integer.parseInt(str.trim()); str=""; } if((char)tc=='\n') { e=Integer.parseInt(str.trim()); arry[v][e]=1; arry[e][v]=1; str=""; } } o.close(); r.close(); FileOutputStream f=new FileOutputStream("F:/Arithmetic/tinyG_matrix.txt"); OutputStreamWriter O=new OutputStreamWriter(f); BufferedWriter w=new BufferedWriter(O); str=""; System.out.println("图的邻接矩阵为 :"); for(int i=0;i<a;i++) { for(int j=0;j<a;j++) { System.out.print(arry[i][j]+" "); str=str+Integer.toString(arry[i][j]); if(j==12){ System.out.println(); w.write(str); w.newLine(); str=""; } } } w.close(); O.close(); } catch(NumberFormatException e) { e.printStackTrace(); } catch(FileNotFoundException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } } }
0 0
- 第四周作业—图的表示
- 第四周作业—图的表示
- 第四周作业—图的表示
- 第四周作业—图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示(GraphRepresentation)
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- 第四周作业——图的表示
- java 学习 BigInteger
- PHPCMS系统初始化流程
- PHP分页
- Excel 2010高级应用-条状图(五)
- ios的self.用法
- 第四周作业——图的表示
- Visual Studio 2010 中的 MSDN 帮助文档
- day03-spring与数据库操作的框架解析即dataSource的获取(JDBC)、使用spring中已经有的事务进行JDBC操作
- 线程资源同步分析
- Pat(Advanced Level)Practice--1070(Mooncake)
- 人生把我当成了戏子,我只好把你们当成婊子
- Spring 资源访问剖析和策略模式应用
- win7中右击“计算机”点“管理” 则出现“该文件没有与之关联的程序来执行操作。
- Makefile编写中参数说明