2018年第九届蓝桥杯省赛 Java A 组真题

2018年第九届蓝桥杯省赛 Java A 组真题

第一题

截屏2021-04-02 15.13.08
import java.util.Calendar;

public class Q1 {
   

	public static void main(String[] args) {
   
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, 2000);
		// 月份从 0 开始
		cal.set(Calendar.MONTH, 0); 
		cal.set(Calendar.DAY_OF_MONTH, 1);
		
		int cnt = 1;
		while (cal.get(Calendar.MONTH) != 4 || cal.get(Calendar.DAY_OF_MONTH) != 4) {
   
			cal.add(Calendar.DAY_OF_MONTH, 1);
			cnt++;
		}
		
		System.out.println(cnt);
	}
}

答案:125

第二题

截屏2021-04-02 15.17.51p1

public class Q2 {
   
	
	static int r = 1000;

	public static void main(String[] args) {
   
		
		int ans = 0;
		for (int i = 1; i <= r; i++) {
   
			for (int j = 1; j <= r; j++) {
   
				if (i * i + j * j <= r * r)
					ans++;
			}
		}
		
		System.out.println(ans * 4);
	}
}

答案:3137548

第三题

截屏2021-04-02 15.21.33
import java.math.BigInteger;

public class Q3 {
   
	
	public static void main(String[] args) {
   
		BigInteger[] ans = pow(new BigInteger("2"), new BigInteger("3"), 123456);
		System.out.println(ans[0] + " " + ans[1] + "i");
	}
	
	static BigInteger[] pow(BigInteger x, BigInteger y, int n) {
   
		if (n == 0) return new BigInteger[] {
   new BigInteger("1"), new BigInteger("0")};
		if (n == 1) return new BigInteger[] {
   x, y};
		if (n % 2 != 0) {
   
			BigInteger[] t = pow(x, y, n - 1)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值