CSDN编程竞赛第6期-参赛心得以及个人题解

CSDN编程竞赛报名地址:https://edu.csdn.net/contest/detail/16
(请不要删掉此地址)

前言/背景

这是第1次参加CSDN的在线编程竞赛,虽然也拿到满分了,但是输在时间用太多了,最后根据比赛奖励,CSDN将会奖励一个电子书阅读月卡。

参赛流程

报名后在指定时间段登陆系统就行了,做题时间最长是2小时,超时未交卷的将自动提交。实际上根本不需要那么长的时间,因为题目难度其实不大。

参赛经历

做题前我先把4道题目都看过一遍,发现难度是递增的,因此也是中规中矩按顺序做题。

解题思路

1、题目名称:严查枪火 X国最近开始严管枪火。 像是“ak”,“m4a1”,“skr”。都是明令禁止的。 现在小Q查获了一批违禁物品其中部分是枪支。 小Q想知道自己需要按照私藏枪火来关押多少人。 (只有以上三种枪被视为违法)

    public static int solution(int n, ArrayList<String> vector){
        int result = 0;
        // TODO: 请在此编写代码
        for(int i = 0; i < vector.size(); i++) {
            String str = (String)vector.get(i);
            if("ak".equals(str) || "m4a1".equals(str) || "skr".equals(str)) {
                result = result + 1;
            }
        }
        return result;
    }

2、题目名称:鬼画符门 鬼画符门,每年都会统计自己宗门鬼画符消耗的数量,往年一直是大师兄管理, 但是这次鬼艺接手了, 你能帮鬼艺写一个 程序统计每年消耗数量最多的鬼画符吗?

    public static String solution(int n, ArrayList<String> vector){
        // TODO: 请在此编写代码
        HashMap<String, Integer> map = new HashMap<>();
        for(int i = 0; i < n; i++) {
            String str = vector.get(i);
            if(map.get(str) == null) {
                map.put(str, 1);
            } else {
                Integer cnt = map.get(str);
                map.put(str, cnt + 1);
            }
        }
        int max = 0;
        String result = "";
        for(String str: map.keySet()) {
            if(max < (Integer)map.get(str)) {
                max = (Integer)map.get(str);
                result = str;
            }
        }
        return result;
    }

3、题目名称:收件邮箱 已知字符串str,str表示邮箱的不标准格式。 其中”.”会被记录成”dot”,”@”记录成”at”。 写一个程序将str转化成可用 的邮箱格式。(可用格式中字符串中除了开头结尾所有”dot”,都会被转换,”at”只会被转化一次,开头结尾的不转化)

    public static String solution(String str){
        String result = "";
        // TODO: 请在此编写代码
        result += str.charAt(0);
        boolean flag = false;
        for(int i = 1; i < str.length() - 1; i++) {
            if(str.charAt(i)=='a' && str.charAt(i+1) == 't' && flag == false) {
                result += '@';
                i = i + 1;
                flag = true;
                continue;
            }
            if(str.charAt(i)=='d' && str.charAt(i+1) == 'o' && str.charAt(i+2) == 't' && i < str.length()-3) {
                result += '.';
                i = i + 2;
                continue;
            }
            result += str.charAt(i);
        }
        result += str.charAt(str.length()-1);
        return result;
    }

4、题目名称:最长递增的区间长度 给一个无序数组,求最长递增的区间长度。如:[5,2,3,8,1,9] 最长区间 2,3,8 长度为 3

    public static int solution(int n, ArrayList<Integer> arr){
        int result = 0;
        // TODO: 请在此编写代码
        int cnt[] = new int[n+1];
        cnt[0] = 1;
        for(int i = 1; i < n; i++) {
            if(arr.get(i-1) < arr.get(i)) {
                cnt[i] = cnt[i-1] + 1;
            } else {
                cnt[i] = 1;
            }
        }
        for(int i = 0; i < n; i++) {
            if(cnt[i] > result) result = cnt[i];
        }
        return result;
    }

经验心得

总的来说比赛有2个难点:一是不允许用本地IDE进行编辑调试;二是参赛选手使用的编程语言各不相同,有些题目对于某些语言来说有现成的方法。建议使用python, java来比赛,用c/c++之类的不推荐

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值