306笔试8.24

//第一题:镜面反转,ABA 为NO,AHA为YES,ABC为NO,只需找到反转后和原来相同的字母('A','H','I','M','O','T','U','V','W','X','Y'),并判断是不是回文
public class Main {

    public static void main(String[] args) {
        Set<Character> set=new HashSet<>();
        Character[] chars={'A','H','I','M','O','T','U','V','W','X','Y'};
        Arrays.stream(chars).forEach(set::add);
        Scanner input=new Scanner(System.in);
        while (input.hasNextLine()){
            System.out.println(IsExcept(set,input.nextLine()));
        }

    }

    private static String IsExcept(Set set,String string) {
        int left=0;
        int right=string.length()-1;
        while (left<=right){
            if (!set.contains(string.charAt(left))||!set.contains(string.charAt(right)))return "NO";
            if (string.charAt(left++)!=string.charAt(right--)){
                return "NO";
            }
        }
        return "YES";
    }
}



//第二题:闯关->只需将无道具的先冲关再将有道具的按照分数从大到小排序即可
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        long n = input.nextLong();
        PriorityQueue<Long> queue = new PriorityQueue<Long>((a, b) -> b.compareTo(a));
        long current=0;
        while (n > 0) {
            long[] item=new long[]{input.nextLong(), input.nextLong()};
            if (item[1]==0){
                current+=item[0];
            }else {
                queue.add(item[0]);
            }
            n--;
        }
        long max = getResult(queue, current);
        System.out.println(max);
    }

    private static long getResult(PriorityQueue<Long> queue, long current) {
        if (queue.isEmpty()) {
            return current;
        } else {
            while (!queue.isEmpty()) {
                current+=Math.max(current,queue.poll());
            }
            return current;
        }
    }
}


#笔试题目##360公司#
全部评论

相关推荐

不愿透露姓名的神秘牛友
今天 11:00
点赞 评论 收藏
分享
头顶尖尖的程序员:我是26届的不太懂,25届不应该是找的正式工作吗?为什么还在找实习?大四还实习的话是为了能转正的的岗位吗
点赞 评论 收藏
分享
05-22 12:44
已编辑
门头沟学院 golang
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-07 12:04
毕业生招你惹你了,问一个发薪日来一句别看网上乱七八糟的你看哪个工作没有固定发薪日扭头就取消了面试就问了一句公司都是这个态度吗还搞上人身攻击了...
程序员小白条:呃呃呃,都还没面试,我都不会问这么细,何况通不通过,去不去都另说,你没实力和学历的话,在外面就这样,说实话没直接已读不回就不错了,浪费时间基本上
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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