BUPT2019网研网安机试Java题解

题目搜集于各位前辈,侵删。

第一题

在这里插入图片描述

//签到题
import java.util.Scanner;

public class i1901 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int t = 0;t<T;t++) {
			int min = Integer.MAX_VALUE;
			for(int i = 0;i<4;i++) {
				min = Math.min(min, sc.nextInt());
			}	
			System.out.println(min);	
		}
		sc.close();
	}
}

第二题

在这里插入图片描述

//闰年判断,easy
import java.util.Scanner;

public class i1902 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int t = 0;t<T;t++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int count = 0;
			for(int i = x;i<=y;i++) {
				if((i%4==0&&i%100!=0)||i%400==0) {
					count++;
				}
			}
			System.out.println(count);
		}
		sc.close();
	}
}

第三题

在这里插入图片描述

//找好下标,每次输出一下链表看一下即可
import java.util.Scanner;

public class i1903 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int t=0;t<T;t++) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int[] arr = new int[n+1];
			for(int i = 1;i<=n;i++) {
				arr[i] = i;
			}
			for(int i = 0;i<m;i++) {
				int op = sc.nextInt();
				if(op == 1) {
					int x = sc.nextInt();
					int flag = 0;//是否遇到x
					for(int j = 1;j<=n-1;j++) {
						if(arr[j] == x) {
							flag = 1;
						}
						if(flag == 1) {
							arr[j] = arr[j+1];
						}
					}
					n--;
				}else if(op == 2) {
					for(int j = 1;j<=n/2;j++) {
						int temp = arr[j];
						arr[j] = arr[n-j+1];
						arr[n-j+1] = temp;
					}
				}else {//op = 3
					int x = sc.nextInt();
					int ans = -1;
					for(int j = 1;j<=n-1;j++) {
						if(arr[j] == x) {
							ans = arr[j+1];
							break;
						}
					}
					if(ans == -1) {
						System.out.println("NONE");
					}else {
						System.out.println(ans);
					}				
				}
//				System.out.print("现在的序列:");
//				for(int j = 1;j<=n;j++) {
//					System.out.print(arr[j]+"  ");
//				}
//				System.out.println();
			}
		}
		sc.close();
	}
}

第四题

没找到原题
听说是最小生成树,把边排序让后并查集控制环即可,其他年份应该会有类似

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值