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公司#
全部评论

相关推荐

不愿透露姓名的神秘牛友
05-26 15:37
1、这群人晚上&nbsp;11&nbsp;点发朋友圈:"凌晨&nbsp;11&nbsp;点,三环的灯还亮着。"&nbsp;实际下班时间:19:30。2、什么是嘉豪呀?我最近在字节实习,没什么时间上网3、同龄人:学校社团、酒吧蹦迪;我:acm、字节/腾讯实习4、别人朋友圈发:“今天不想上课”;我朋友圈发:“今天的班就上到这里啦”,定位:字节跳动5、别人的朋友圈都是到处旅游的定位,我的朋友圈天天都是“字节定位”,还一定要是在【公司的健身房】里拍张照片,实际只练了10分钟,其中凹造型5分钟6、mentor布置任务的时候,别人都是:”好的收到“,我:”是不是要xxxx,xxxx这么做也可以吧,这个技术方案会不会更好些“7、别人书包里装的:王道408、轻薄本、四六级真题。我书包里面装的:显存24GB4090独显gpu(24小时开机运行,屏幕上贴着“字节/腾讯等贴纸”)、速效救心丸(代码报错用)、电棍(熬夜写代码困了用),就很……你们懂吧8、入职大厂第一件事:发朋友圈、发小红书,晒工牌,985计算机硕|字节实习生|可以接咨询|有偿改简历,9、别人的社交软件简介:25岁|男|希望遇见有趣的灵魂;嘉豪的社交软件简介:25岁|程序员|字节跳动工程师|一张佩戴工牌的自拍照大厂嘉豪标配:1.&nbsp;挂胸前的工牌(地铁里只挂不收,怕你看不见&nbsp;logo)2.&nbsp;降噪耳机(不放音乐也戴着,避免别人跟自己说话)3.&nbsp;印&nbsp;logo&nbsp;的电脑包(字节红&nbsp;/&nbsp;腾讯蓝&nbsp;/&nbsp;阿里橙&nbsp;/&nbsp;美团黄)4.&nbsp;手表(最好显示心率,午饭后必发"步数已破&nbsp;6,000")
布布永不言弃:可曾见过“我在未上市小厂实习,丢人了xxx”,然后接着说“这个小厂的创始人是张一鸣” 然后别人要是真不认识张一鸣 就直接急了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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