第十四届蓝桥杯校赛第一场部分题目解法(2 3 4 6 7)

这篇博客分享了作者在第十四届蓝桥杯校赛中的解题思路和代码实现,包括十进制整数转二进制、晨跑天数计算、调和级数求和、山谷字母矩阵检测、核酸天数计算以及元音字母转大写等算法问题的解决方案。通过实例展示了如何运用编程技巧解决竞赛题目。
摘要由CSDN通过智能技术生成

第十四届蓝桥杯校赛第一场部分题目解法(2 3 4 6 7)

  1. 十进制整数
  2. 晨跑
  3. 调和级数
  4. 山谷字母矩阵
  5. 核酸天数计算
  6. 元音字母转大写

序言

只做出来这几个 其他的属实不会 求大佬们指点

1.十进制整数

第一个题直接十进制转二进制 查个数 

2.晨跑

通过20220101-20221231之间的数取余等操作,取出每月的天数和星期 进行判断累加晨跑天数
public class Test2 {
	public static void main(String[] args) {
		int w=6;
		int runday=0;
		for(int i=20220101;i<=20221231;i++) {
			int day=i%100;
			int month=(i%10000)/100;
			int week=w%7;
			if(month==0||month>12) {
				continue;
			}
			if(day==0||day>31) {
				continue;
			}
			//二月特殊28天
			if(month==2&&day>28) {
				continue;
			}
			if((month==4||month==6||month==9||month==11)&&day>30) {
				continue;
			}
			if(week==6||week==0||day==1||day==11||day==21||day==31) {
				runday++;
				w++;
				continue;
			}
			w++;
		}
		System.out.println(runday);
	}
}

3.调和级数

public class Test3 {
	public static void main(String[] args) {
		double S=0;
		int n=0;
		while(S<=12) {
			S+=1.0/(n+1);
			n++;
		}
		System.out.println(n);
	}
}

4.山谷字母矩阵

此题解法是判断字母所在位置是否比上下左右四位的数都小
import java.util.Scanner;

public class Test4 {
	public static void main(String[] args) {
		int count=0;
		Scanner sc=new Scanner(System.in);
		String [] arr=new String [30];
		for (int i = 0; i < arr.length; i++) {
			arr[i]=sc.next();
		}
		for (int i = 1; i <29; i++) {
			for (int j = 1; j <59; j++) {
				if(arr[i].charAt(j)<arr[i-1].charAt(j)&&arr[i].charAt(j)<arr[i+1].charAt(j)&&arr[i].charAt(j)<arr[i].charAt(j-1)&&arr[i].charAt(j)<arr[i].charAt(j+1)) {
					count++;
				}
			}
		}
		System.out.println(count);
		sc.close();
	}
}

6.核酸天数计算

import java.util.Scanner;

public class Test6 {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int s=sc.nextInt();
		int t=sc.nextInt();
		int day=0;
		if(s<t) {
			day=t-s;
		}else {
			day=t+7-s;
		}
		System.out.println(day);
		sc.close();
	}
}

7.元音字母转大写

import java.util.Scanner;

public class Test7 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String str=sc.next();
		String str2="";
		for (int i = 0; i < str.length(); i++) {
			char ch=str.charAt(i);
			if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u') {
				//先将字符ch转换为整型计算ASCII码,大小写相差32,再转换成字符输出
				ch=(char)((int)ch-32);
			}
			str2+=ch;
		}
		System.out.println(str2);
		sc.close();
	}

}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值