跟谁学Java笔试

6道选择,其中一道多选
三道编程
一共60分钟
编程1:
在跟谁学学习的途途小朋友有一天向老师求助,原来途途的父母要出差几天,走之前给途途留下了一些棒棒糖。途途决定每天吃的棒棒糖数量不少于前一天吃的一半,但是他又不想在父母回来之前的某一天没有棒棒糖吃,他想让老师帮他计算一下,他第一天最多能吃多少个棒棒糖。
编程2:
不使用库函数,实现对输入的整数求平方根,结果四舍五入精确到小数点后3位。
编程3:
将一个N阶方阵原地转置。

#高途##Java工程师##校招##面经#
全部评论
第二题有人贴吗,菜鸡只会leetcode的取整版,保留3位小数怎么做噢
2 回复 分享
发布于 2021-03-12 13:29
第一题好像可以二分答案,不知道有没有贪心解。
1 回复 分享
发布于 2021-03-11 20:47
最后一个矩阵的可以输入的时候直接放到转置之后的位置上
1 回复 分享
发布于 2021-03-11 20:35
第一题一直50%🤣
1 回复 分享
发布于 2021-03-11 20:30
贴一下第三题,虽然写得捞 import java.util.*; public class Main {     public static void main(String[] args) {         Scanner in = new Scanner(System.in);         int n = in.nextInt();         int[][] matrax = new int[n][n];         for (int i = 0; i < n; i++) {             for (int j = 0; j < n; j++)                 matrax[i][j] = in.nextInt();         }         for (int i = 0; i < n; i++)             for (int j = i; j < n; j++) {                 int temp = matrax[i][j];                 matrax[i][j] = matrax[j][i];                 matrax[j][i] = temp;             }         for (int i = 0; i < n; i++)             for (int j = i; j < n; j++)                 System.out.println(matrax[i][j]);     } }
1 回复 分享
发布于 2021-03-11 20:05
发一下第二题吧,错了请指正 public class Pingfanggen { //求平方根 public static void main(String[] args) { Scanner s = new Scanner(System.in); int n =s.nextInt(); String aString = String.format("%.3f",kaifang(n)); System.out.println(aString); } public static double kaifang(int n) { Double a = 1.0; Double b = n+0.0; while(a<b) { Double c = (a+b)/2.0; if((c*c-b)/0.001<1) { return c; } if(c*c<b) { a=c; b=(n+0.0)/c; }else if(c*c>b) { b=c; a=(n+0.0)/c; } else { return a; } } return a; } }
点赞 回复 分享
发布于 2021-03-17 10:04
3.  class Solution {     public int[][] transpose(int[][] matrix) {         int m = matrix.length;         int n= matrix[0].length;         int[][] res = new int[n][m];         for(int i=0;i<m;i++){             for(int j=0;j<n;j++){                 res[j][i]=matrix[i][j];             }         }         return res;     } }
点赞 回复 分享
发布于 2021-03-12 08:06
第三题sout4测试用例过61%
点赞 回复 分享
发布于 2021-03-12 00:15
第一题代码
点赞 回复 分享
发布于 2021-03-11 20:21

相关推荐

头像
04-17 09:29
已编辑
湖南农业大学 后端
睡姿决定发型丫:本硕末9也是0offer,简历挂了挺多,只有淘天 美团 中兴给了面试机会,淘天二面挂,美团一面kpi面,中兴一面感觉也大概率kpi(虽然国企,但一面0技术纯聊天有点离谱吧)
点赞 评论 收藏
分享
评论
点赞
10
分享

创作者周榜

更多
牛客网
牛客企业服务