第一次被笔试输入恶心到头疼
我绷不住了,今晚的笔试做的恶心,这个输入是有病吗?为什么不给输入数组的行数和列数,还是子符串类型,为什么不搞核心代码模式呢?我想问一下!!!输入改成数组改半天,顺便有没有大佬知道这样该怎么搞,还得先判断数组行数和列数吗?
import java.util.Scanner; public class Juren0923 { static int max =0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); System.out.println(getMax(s)); } private static int getMax(String s) { int ans=0; int[][] grid= new int[?][?];?????? int hang =0; int lie=0; for (int i = 0; i < s.length(); i++) { if(s.charAt(i)-'0'>=0&&s.charAt(i)-'0'<=9){ grid[hang][lie] = s.charAt(i)-'0'; lie++; }else if(i>0&&s.charAt(i)==','&&s.charAt(i-1)==']'){ lie=0; hang++; }else{ continue; } } dfs(grid,0,0,ans); return max; } private static void dfs(int[][] grid,int x,int y,int ans){ if(x>=grid.length||y>=grid[0].length){ return ; } if(x== grid.length-1&&y==grid.length-1){ max = Math.max(ans,max); return; } ans += grid[x][y]; dfs(grid,x+1,y,ans); dfs(grid,x,y+1,ans); }
#笔试#