流利说笔试题第二题 猫捉老鼠 求输入写法
输入为一个多行矩阵,例如
2 0 0 1
0 1 0 1
1 0 0 0
3 0 1 0
求2到3的最短距离,0能过1不能过,我知道是BFS,不过输入没有指定行列多少,怎么写输入
我是这么写的,但是会多回车一行才能往下走代码
Scanner sc = new Scanner(System.in); List<String> list = new ArrayList<>(); while (sc.hasNextLine()) { String s = sc.nextLine(); if(s==null||"".equals(s)) { break; } list.add(s); //System.out.println(s); } int row = list.size();
但是这样多一行啊,求大佬指教该怎么写输入啊?
#笔试题目##流利说#