360笔试第一题,求表面积,大佬看看问什么ac 0

#360公司##笔试题目#
全部评论
ac100%,明天贴代码
点赞 回复 分享
发布于 2019-08-15 21:48
我ACl18.9%
点赞 回复 分享
发布于 2019-08-15 21:27
AC 100的代码 import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner=new Scanner(System.in); while(scanner.hasNext()) { int N=scanner.nextInt(); int M=scanner.nextInt(); int[][] all=new int[N][M]; for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { all[i][j]=scanner.nextInt(); } } int top=N*M; int num=0; for(int i=0;i<N;i++) { for(int j=0;j<M;j++) { if(i>0&&all[i][j]>all[i-1][j]) { num+=all[i][j]-all[i-1][j]; } if(j>0&&all[i][j]>all[i][j-1]) { num+=all[i][j]-all[i][j-1]; } if(i<N-1&&all[i][j]>all[i+1][j]) { num+=all[i][j]-all[i+1][j]; } if(j<M-1&&all[i][j]>all[i][j+1]) { num+=all[i][j]-all[i][j+1]; } if(i==0) num+=all[i][j]; if(j==0)     num+=all[i][j]; if(i==N-1) num+=all[i][j]; if(j==M-1) num+=all[i][j]; } } int result=top*2+num; System.out.println(result); } } }
点赞 回复 分享
发布于 2019-08-16 10:39
楼主有输出吗= =
点赞 回复 分享
发布于 2019-08-15 22:07
是不是因为没有循环输入。 public class Main1 {     public int getSum(int[][] cube, int M, int N){         int sum = 0;         for(int temi = 1; temi <= M; temi++){             int temsum = 0;             for(int temj = 1; temj <= N; temj++){                 int val = cube[temi][temj];                 temsum += (val > cube[temi-1][temj])?val-cube[temi-1][temj]:0;                 temsum += (val > cube[temi+1][temj])?val-cube[temi+1][temj]:0;                 temsum += (val > cube[temi][temj-1])?val-cube[temi][temj-1]:0;                 temsum += (val > cube[temi][temj+1])?val-cube[temi][temj+1]:0;             }             sum += temsum;         }         return sum;     }     public static void main(String[] args){         Scanner sc = new Scanner(System.in);         Main1 obj = new Main1();         while(sc.hasNext()){             int M, N;             M = sc.nextInt();             N = sc.nextInt();             int[][] cube = new int[M+2][N+2];             for(int temi = 1; temi <= M; temi++){                 for(int temj = 1; temj <= N; temj++){                     cube[temi][temj] = sc.nextInt();                 }             }             int sum = obj.getSum(cube, M, N);             System.out.println(sum+2*M*N);         }     } }
点赞 回复 分享
发布于 2019-08-15 21:58
你这读数据的函数没对吧,in.nextLine()是不是把下一行给读进去了?下面的代码应该是没错的
点赞 回复 分享
发布于 2019-08-15 21:47
分享下我的思路 public void first() {         Scanner scanner = new Scanner(System.in);         int N = scanner.nextInt();         int M = scanner.nextInt();         int[][] nums = new int[N + 2][M + 2];         int result = 0;         for (int i = 1; i <= N; i++) {             for (int j = 1; j <= M; j++) {                 nums[i][j] = scanner.nextInt();             }         }         for (int i = 1; i <= N; i++) {             for (int j = 1; j <= M; j++) {                 if (nums[i][j] < 1) {                     continue;                 }                 int ***Num = nums[i][j];                 result += 2;                 int up = ***Num - nums[i - 1][j];                 int down = ***Num - nums[i + 1][j];                 int left = ***Num - nums[i][j - 1];                 int right = ***Num - nums[i][j + 1];                 if (up > 0) {                     result += up;                 }                 if (down > 0) {                     result += down;                 }                 if (left > 0) {                     result += left;                 }                 if (right > 0) {                     result += right;                 }             }         }         System.out.println(result);     }
点赞 回复 分享
发布于 2019-08-15 21:37

相关推荐

不愿透露姓名的神秘牛友
昨天 17:13
想去,但是听说加班强度实在难崩,所以拒绝了,现在有点心梗对面hr感觉也是实习生,打电话的时候怪紧张的,但是感觉人很好嘞
水中水之下水道的鼠鼠:哥们这不先去体验一下,不行再跑呗,大不了混个实习经历(有更好的转正offer就当我没说)
点赞 评论 收藏
分享
矫健的闭门羹烹饪师又...:本人双非本,在鹅厂测开实习,你这个简历上写的这两个项目的技术栈都差不多,能够让面试官去延伸去问的八股除了redis就再没啥了,建议项目这边可以再改改,然后专业技能那块的话,感觉linux和测试工具可以分开写,毕竟不是干一件事的,反正没实习的基础上面试就深挖项目和八股,好好卷吧
听劝,我这个简历该怎么改...
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务