蓝桥杯java省赛第七题

第十一届2020-4单词分析(15分)

import java.util.Scanner;

public class g2020{
        public static void main(String[] args) {
            Scanner sc = new Scanner (System.in);
            String s = sc.nextLine();
            int max = 0;
            int index = 0;
            String a = "abcdefghijklmnopqrstuvwxyz";
            int b[] = new int[26];

            for(int i = 0;i<s.length();i++){
                b[a.indexOf(s.charAt(i))]++;
            }
            for(int j = 0;j<b.length;j++){
                if(b[j]>max){
                    max = b[j];
                    index = j;
                }

            }
            System.out.println(a.substring(index,index+1));
            System.out.println(max);
        }}

第十届2019-4外卖优先级(15分)

package g;
import java.util.HashMap;
import java.util.Scanner;
public class g2019 {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int m = cin.nextInt();
        int t = cin.nextInt();
        //首先我们需要有一张关于店铺Id和时间的二维数组
        int[][] orderShops = new int[n+1][t+1];
        //然后我们需要显示店铺的优先级
        int[] countShops = new int[n+1];
        //分别输入m行ts时刻id店铺设置为一
        HashMap<Integer,Integer> hashMap = new HashMap<>();
        for(int i =0;i<m;i++){
            int ts = cin.nextInt();
            int id = cin.nextInt();
            orderShops[id][ts] ++;
        }

        for(int i =1;i <= n;i++){
            for(int j =1;j <= t;j++){
                //在j时刻店铺i没有订单,优先级减1
                if(orderShops[i][j]==0){
                    countShops[i] = Math.max(0,countShops[i]-1);
                }else {
                //有订单的时候
                    countShops[i] +=orderShops[i][j]*2;
                }
                //每个时刻都需要自己去不断刷新,然后判断哪些在缓存对列的去留
                if(countShops[i] >5){
                    hashMap.put(i,1);
                }
                if(countShops[i] <=3 && hashMap.containsKey(i)){
                    hashMap.remove(i);
                }
            }
        }
        System.out.println(hashMap.size());
        cin.close();
    }
}

第九届2018-4递增三元组(15分)

package g;
import java.util.Arrays;
import java.util.Scanner;
public class g2018 {
    public static void main(String[] args) {
        long ans=0;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        int[] B = new int[n];
        int[] C = new int[n];
        for (int i = 0; i < n; i++)
            A[i] = sc.nextInt();
        for (int i = 0; i < n; i++)
            B[i] = sc.nextInt();
        for (int i = 0; i < n; i++)
            C[i] = sc.nextInt();
        Arrays.sort(A);
        Arrays.sort(B);
        Arrays.sort(C);
        int p=0;
        int q=0;
        for(int i=0;i<n;i++){
            while(p<n&&A[p]<B[i])p++;
            while(q<n&&C[q]<=B[i])q++;
            ans+=p*(n-q);
        }
        System.out.println(ans);   }}

第八届2017-4日期问题(15分)

// A code block
var foo = 'bar';

第七届2016-4剪邮票(15分)

// A code block
var foo = 'bar';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值