快手笔试第一题

这样为什么是 0% 呀!

import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = Integer.parseInt(scanner.nextLine());
        while (--m >= 0) {
            String s = scanner.nextLine();
            String[] str = s.split(" ");
            String[] s1 = str[0].split("\\.");
            String[] s2 = str[1].split("\\.");
            long x;
            if (s1.length == 1) {
                x = Long.parseLong(s1[0]);
            } else {
                x = help(s1);
            }
            long y;
            if (s2.length == 1) {
                y = Long.parseLong(s2[0]);
            } else {
                y = help(s2);
            }
            if (x < y) {
                System.out.println(true);
            } else {
                System.out.println(false);
            }
        }
    }

    public static long help(String[] c1) {
        int[] nums = new int[c1.length];
        for (int i = 0; i < c1.length; ++i) {
            if (i == 0) {
                while (i < c1.length && Integer.parseInt(c1[i]) == 0) {
                    i++;
                }
                if (i == c1.length) {
                    break;
                }
            }
            nums[i] = Integer.parseInt(c1[i]);
        }
        StringBuilder sb = new StringBuilder();
        for (int i = nums.length - 1; i >= 0; --i) {
            if (i == nums.length - 1) {
                while (i >= 0 && nums[i] == 0) {
                    i--;
                }
                if (i < 0) {
                    break;
                }
            }
            sb.append(nums[i]);
        }
        String res = sb.toString();
        long x;
        try {
            x = Long.parseLong(res);
        } catch (Exception e) {
            return 0;
        }
        return x;
    }
}


#快手##笔试题目##秋招#
全部评论
同0,本地花样测,提交一点测试用例都过不了?真不信。
点赞 回复
分享
发布于 2019-08-25 18:39
LeetCode165 https://blog.csdn.net/weixin_40550726/article/details/82909342
点赞 回复
分享
发布于 2019-08-25 18:41
滴滴
校招火热招聘中
官网直投
#include<iostream> #include<string> #include<cstdio> #include<algorithm> using namespace std; int main() {     int n;     char A[10010],B[10010];     scanf("%d",&n);     while(n--)     {         scanf("%s%s",A,B);         int len_a=strlen(A);         int len_b=strlen(B);         int num_1[4];         int num_2[4];         for(int i=0;i<4;++i)         {             num_1[i]=0;             num_2[i]=0;         }         int ctor=0;         for(int i=0;i<len_a;++i)         {             if(A[i]=='.')             {                 ctor++;             }             else             {                 num_1[ctor]=num_1[ctor]*10+A[i]-'0';             }         }         ctor=0;         for(int i=0;i<len_b;++i)         {             if(B[i]=='.')             {                 ctor++;             }             else             {                 num_2[ctor]=num_2[ctor]*10+B[i]-'0';             }         }         int flag=0;         for(int i=0;i<4;++i)         {             if(num_1[i]<num_2[i])             {                 flag=1;                 break;             }         }         if(flag)             printf("true\n");         else             printf("false\n");     }     return 0; } //1 //1 1.0.0.2 为啥我的也是 0% ,哪里有问题?
点赞 回复
分享
发布于 2019-08-25 18:43
会不会是输出的问题?
点赞 回复
分享
发布于 2019-08-25 18:53
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Question_1 { public static void main(String[] args) throws NumberFormatException, IOException { // TODO Auto-generated method stub BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int m = Integer.parseInt(br.readLine()); List<String[]> list = new ArrayList(); for (int i = 0; i < m; i++) { String[] str = br.readLine().split(" "); list.add(str); } for (int i = 0; i < list.size(); i++) { String[] str = list.get(i); String[] str1 = str[0].split("\\."); int[] arr1 = new int[str1.length]; for (int j = 0; j < str1.length; j++) { arr1[j] = Integer.parseInt(str1[j]); } String[] str2 = str[1].split("\\."); int[] arr2 = new int[str2.length]; for (int j = 0; j < str2.length; j++) { arr2[j] = Integer.parseInt(str2[j]); } System.out.println(com(arr1, arr2)); } } public static boolean com(int[] arr1, int[] arr2) { int len = Math.max(arr1.length, arr2.length); int[] temp1 = new int[len]; int[] temp2 = new int[len]; for (int i = 0; i < arr1.length; i++) temp1[i] = arr1[i]; for (int i = 0; i < arr2.length; i++) temp2[i] = arr2[i]; boolean flag = false; for (int i = 0; i < temp1.length; i++) { if (temp1[i] > temp2[i]) { flag = false; break; } else if (temp1[i] < temp2[i]) { flag = true; break; } else continue; } return flag; } } //还有一个情况要记住,就是版本号相同也要输出false,不升级
点赞 回复
分享
发布于 2019-08-25 19:07
同问!!!我也是0,枯了,测试用例两个都没问题
点赞 回复
分享
发布于 2019-08-25 19:07
同0,本地能过。。。浪费了我几十分钟时间。凉
点赞 回复
分享
发布于 2019-08-25 20:28
我过了 🙄
点赞 回复
分享
发布于 2019-08-25 20:30
else if (x > y) {     ..... } 再加这个判断就行了
点赞 回复
分享
发布于 2019-08-25 22:31

相关推荐

点赞 1 评论
分享
牛客网
牛客企业服务