0
点赞
收藏
分享

微信扫一扫

【蓝桥杯】每日一题进击国赛

九月的栩 2022-03-24 阅读 61

👉今日份搞题 👈

🥇1.集合运算

import java.util.*;
 
public class Main
{
    public static void main(String args[])
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.valueOf(br.readLine());
		String[] s=br.readLine().split(" ");
		Set<Integer> set1=new TreeSet<Integer>();
		Set<Integer> set2=new TreeSet<Integer>();
		Set<Integer> result=new TreeSet<Integer>();
		for (int i = 0; i <n; i++) {
			set1.add(Integer.valueOf(s[i]));
		}
		int m=Integer.valueOf(br.readLine());
		s=br.readLine().split(" ");
		for (int i = 0; i < m; i++) {
			set2.add(Integer.valueOf(s[i]));
		}
		//交集
		result.clear();
		result.addAll(set1);
		result.retainAll(set2);
		for (int i : result) {
			System.out.print(i+" ");
		}
		if (result.size()!=0) {
			System.out.println();
		}
		//并集
		result.clear();
		result.addAll(set1);
		result.addAll(set2);
		for (int i : result) {
			System.out.print(i+" ");
		}
		//差集
		result.clear();
		result.addAll(set1);
		result.removeAll(set2);
		for (int i : result) {
			System.out.println();
			System.out.print(i+" ");
		}
    }
}

🥈寂寞的数

import java.util.*;
 
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n+1];
		for (int i = 0; i <=n; i++) {
			int x=i;
			int y=i;
			while(x!=0) {
				y+=x%10;
				x/=10;
			}
			if (y<=n) {
				a[y]=1;
			}
		}
		for (int i = 1; i <=n; i++) {
			if (a[i]==0) {
				System.out.println(i);
			}
		}
    }
}

🥉数组逆序排列

import java.util.*;
 
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
		int a[]=new int[21];
		int b=0;
		for (int i = 0; i < a.length; i++) {
			a[i]=sc.nextInt();
			if (a[i]==0) {
				break;
			}
			b++;
		}
		for (int i = b-1; i >=0; i--) {
			System.err.print(a[i]+" ");
		}
    }
}

💫写在最后

        离蓝桥杯省赛越来越近了,大家抓紧刷题把,争取拿省一。

                           倒计时:16-day

举报

相关推荐

0 条评论