08-06科大讯飞开发笔试

第一题:给出以“ ”隔开的字符串,找出字符串中包含‘e’的单词个数
第二题:给出四个点,计算四边形的面积。
static class Point{
    int x;
    int y;
    public Point(int x, int y){
        this.x = x;
        this.y = y;
    }
}
public static void main(String[] args) {
    Point p1 = new Point(1,1);
    Point p2 = new Point(2,2);
    Point p3 = new Point(1,3);
    Point p4 = new Point(0,2);
    long area = getArea(p1,p2,p3,p4);
    System.out.println(area);
}
private static long getArea(Point p1, Point p2, Point p3, Point p4) {
    // 两点的长度:√((x1-x2)^2 + (y1-y2)^2))
    double len12 =  Math.sqrt(Math.pow(p1.x - p2.x,2) + Math.pow(p1.y - p2.y,2));
    double len23 =  Math.sqrt(Math.pow(p2.x - p3.x,2) + Math.pow(p2.y - p3.y,2));
    double len34 =  Math.sqrt(Math.pow(p3.x - p4.x,2) + Math.pow(p3.y - p4.y,2));
    double len41 =  Math.sqrt(Math.pow(p4.x - p1.x,2) + Math.pow(p4.y - p1.y,2));
    // 利用这条边将四边形切割开
    double len24 =  Math.sqrt(Math.pow(p4.x - p2.x,2) + Math.pow(p4.y - p2.y,2));
    // 海伦公式:半周长:k=(a+b+c)/2, 面积:s = √(k(k-a)(k-b)(k-c)) 
    double k1 = (len41 + len12 + len24) / 2;
    double k2 = (len23 + len34 + len24) / 2;
    double s1 = Math.sqrt(k1 * (k1 - len41) * (k1 - len12) * (k1 - len24));
    double s2 = Math.sqrt(k2 * (k2 - len23) * (k2 - len34) * (k2 - len24));
    // 这里加0.5是为了四舍五入
    return (long)(s1 + s2 + 0.5);
}
第三题:lc115,不同的子序列
public static void main(String[] args) {
    String str = "iflytekiflytek";
    int res = findIflytek(str);
    System.out.print(res);
}
public static int findIflytek (String str) {
    // write code here
    String s = "iflytek";
    int n = str.length();
    int m = s.length();
    int[][] dp = new int[m + 1][n + 1];
    for (int i = 0; i <= n; i++) dp[0][i] = 1;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(s.charAt(i - 1) == str.charAt(j - 1)){
                dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
            }else{
                dp[i][j] = dp[i][j - 1];
            }
        }
    }
    return dp[m][n];
}


#科大讯飞笔试#
全部评论
第二题代码应该是有问题的,如果是这样的形状,就不行
1 回复 分享
发布于 2022-08-07 13:06
第三题没看出来原题,回溯过了百分之33,😅
1 回复 分享
发布于 2022-08-06 22:40
楼主是A卷嘛
点赞 回复 分享
发布于 2022-08-09 10:33
这个第三题不是还有大小写吗,为啥这样也可以过呢?
点赞 回复 分享
发布于 2022-08-08 18:32
楼主什么时候投递的,我测评做完一直不安排笔试,是不是测评挂了
点赞 回复 分享
发布于 2022-08-07 14:53
过分了,怎么没看到和我一样三道题的,电台覆盖超时吐了
点赞 回复 分享
发布于 2022-08-07 13:45
用了一个小时,第二题没做出来。
点赞 回复 分享
发布于 2022-08-07 10:33
第二题我求两个三角形面积时四舍五入了,盖了帽了,只通过30%,应该最后四舍五入!!!
点赞 回复 分享
发布于 2022-08-07 08:56
第二题我样例通过了,测试通过0就离谱
点赞 回复 分享
发布于 2022-08-06 22:26

相关推荐

猛干:你怎么当孝子都和我时间一样😭
点赞 评论 收藏
分享
评论
1
9
分享

创作者周榜

更多
牛客网
牛客企业服务