栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

ccfcsp认证历年考试 java 解题随手记(1,2题)持续更新

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ccfcsp认证历年考试 java 解题随手记(1,2题)持续更新

201312-1 出现次数最多的数
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        HashMap mp = new HashMap<>();
        int n = sc.nextInt();
        int[] arr = new int[]{0,0};
        for (int i = 0; i < n; i++) {
            int p = sc.nextInt();
            mp.put(p,mp.getOrDefault(p,0)+1);
        }
        for(Integer key:mp.keySet()){
            if(mp.get(key)>arr[1]){
                arr[1] = mp.get(key);
                arr[0] = key;
            }else if(mp.get(key)==arr[1] &&key
201312-2  ISBN号码  
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String[] st = sc.next().split("-");
        String ss = st[0]+st[1]+st[2];
        int count = 0;
        for(int i =0;i 
 201403-1  相反数 
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count=0;
        HashSet hs = new HashSet<>();
        for (int i = 0; i < n; i++) {
            int a =  Math.abs(sc.nextInt());
            if(hs.contains(a)){
                count++;
            }else {
                hs.add(a);
            }
        }
        System.out.println(count);
    }
}
201403-2  窗口
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList  windows  = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int[] window = new int[5];
            window[0] = i+1;
            for (int j = 1; j < 5; j++) {
                window[j] = sc.nextInt();
            }
            windows.add(window);
        }
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            boolean b = true;
            for (int j = n-1; j >=0 ; j--) {
                if(is_in(x,y,windows.get(j))) {
                    System.out.println(windows.get(j)[0]);
                    int[] w = windows.remove(j);
                    windows.add(w);
                    b =false;
                    break;
                }
            }
            if (b){
                System.out.println("IGNORED");
            }
        }
    }
    static boolean is_in(int x, int y,int[] window){
        int x1 = window[1];
        int y1 = window[2];
        int x2 = window[3];
        int y2 = window[4];
        return  x1<=x && x<=x2  && y1<=y && y<=y2;
    }
}
201409-1  相邻数对
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        //系统自带小根堆,可以直接将输入的数据进行排序
        PriorityQueue heap = new PriorityQueue<>();
        for (int i = 0;i 
201409-2  画图 
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashSet hset = new HashSet<>();
        for (int i = 0; i < n; i++) {
            int x1 = sc.nextInt();
            int y1 = sc.nextInt();
            int x2 = sc.nextInt();
            int y2 = sc.nextInt();
            for (int j = x1; j  
201412-1  门禁系统 
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashMap hmap = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int r = sc.nextInt();
            hmap.put(r,hmap.getOrDefault(r,0)+1);
            System.out.print(hmap.get(r)+" ");
        }
    }
}
201412-2  Z字形扫描

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/929948.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号