在赛码网上笔试,本地找不出问题来,但是一提交就是百分之0

在赛码网上笔试,本地找不出问题来,但是一提交就是百分之0,真的好多题目了,实在不知道怎么解决,恳请java大神指点一二
这个是携程笔试的那个二分查找: /**
 * 请写一个二分查找算法查找一个数最先出现的index,如果数不在集合中需要返回(-1)-当前数应该出现的位置。
 * 例如 [1,3,6],查找5,5应该是在index=2的位置但并不在集合中。返回(-1)-2 = -3。
 */
import java.util.Scanner;
public class BinarySearch {
    public static void main(String[] arg)
    {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int num=scan.nextInt();
        int [] array=new int[num];
        for(int i=0;i<num;i++)
        {
            array[i]=scan.nextInt();
        }
        int number=-1;
        int front = 0;
        int tail = array.length - 1;
        while (front <= tail) {
            int middle = (front + tail) / 2;
            if (array[middle] == n) {
                number=middle;
                break;
            } else if (array[middle] > n) {
                tail = middle - 1;
            } else {
                front = middle + 1;
            }
        }
        if(number==-1) {
            number = (-1) - front;
        }
        System.out.println(number);
    }
} 

下面这个是今天网易互娱的第一道题目:
import java.util.*;
public class DanCi {
    public static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        while(scan.hasNext())
        {
            int lines=scan.nextInt();
            scan.nextLine();
            HashMap<String,Integer> map=new HashMap<String,Integer>();
            for(int i=0;i<lines;i++)
            {
                String str=scan.nextLine();
                String[] strs=str.split(" ");
                int num=Integer.parseInt(strs[0]);
                for(int j=1;j<=num;j++)
                {
                    String s=strs[j];
                    if(map.containsKey(s)) {
                        int temp=map.get(s);
                        temp++;
                        map.put(s,temp);
                    }
                    else
                        map.put(s,1);
                }
            }
            int count=scan.nextInt();
            Set<Map.Entry<String,Integer>> set=map.entrySet();
            Iterator<Map.Entry<String,Integer>> it=set.iterator();
            ArrayList<Integer> list=new ArrayList<Integer>();
            while(it.hasNext())
            {
                Map.Entry<String,Integer> entry = it.next();
                list.add(entry.getValue());
            }
            Collections.sort(list);
            Collections.reverse(list);
            int countt=0;
            for(int i=0;i<count&&countt<count;i++)
            {
                ArrayList<String> strsb=new ArrayList<String>();
                Set<Map.Entry<String,Integer>> set1=map.entrySet();
                Iterator<Map.Entry<String,Integer>> it1=set1.iterator();
                while(it1.hasNext())
                {
                    Map.Entry<String,Integer> entry = it1.next();
                    if(entry.getValue()==list.get(i))
                    {
                        strsb.add(entry.getKey() + " " + entry.getValue());
                    }
                }
                Collections.sort(strsb);
                if(countt<count)
                {
                    if(strsb.size()==1) {
                        System.out.println(strsb.get(0));
                        countt++;
                    }
                    else {
                        for (int j = 0; j < strsb.size(); j++) {
                            System.out.println(strsb.get(j));
                            countt++;
                            if(countt>=count)
                                break;
                        }
                    }
                }
            }
        }
    }
} 

头疼好几天了、、、诚心跪求指点
全部评论
没做过 ACM 的做赛码就是坑 讲道理 个人已经习惯牛客了 之前还没装IDE 本地记事本写 真坑
点赞 回复 分享
发布于 2016-09-20 22:55
赛码网都是要自己写输入的,牛客函数都规定好了
点赞 回复 分享
发布于 2016-09-20 22:35
赛码网真心没有牛客好,我本地明明是对的,怎么就出问题呢
点赞 回复 分享
发布于 2016-09-19 16:21
第一个,类名要Main 第二个,循环取值,也就是把所有逻辑都放在while循环里:
点赞 回复 分享
发布于 2016-09-19 15:58
我知道了。。。。赛码网上所有的类都要是Main。。。楼主被坑哭了。。。小伙伴们要注意啊。。。
点赞 回复 分享
发布于 2016-09-19 15:47
把读取输入for循环去掉试试
点赞 回复 分享
发布于 2016-09-19 15:46
二分查找的那题,是要找第一次出现num的位置,比如从1,2,2,3找2应该输出1而不是2
点赞 回复 分享
发布于 2016-09-19 15:45

相关推荐

评论
点赞
1
分享

创作者周榜

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