2020年第十一届蓝桥杯省赛第二场Java大学B组部分真题及解析

2021省赛前热身,做几道,分享自己的想法同时学习大家的思路!

A:门牌制作

A-2020
方法:作为第一题,直接暴力:遍历


public class A2020 {
	public static void main(String[] args){
		int count = 0;	
		for(int j= 1; j <=2020; j++){	
			int i = j;
			while(i != 0 ){
				int thismod = i % 10;
					if(thismod == 2){
						count++;
					}
					i = i/10;
				}		
		}
		System.out.print(count);
	}
}

正确答案:624




C:蛇形填数

C-2020
方法:这个题可以直接计算,写一下整体的思维吧

从图形上看这个题是类似于杨辉三角,当把题目从左上看到右下的时候,观察自然序列n和题设序列x之间的关系可以发现x = (n+1)/2

mind-1

因此要求的20行20列数字就是第39行的第20个数字,等差公式计算得第38行最后一个数字应该是741

故得 741+20=761

正确答案:761




F:成绩分析

F-2020
F-2020-2

方法:常规操作比大小,求均值
注意格化输出平均值 ! ! !

方案代码:

public class F2020 {
	public static void main(String[] args){
		int g_max = 0,g_min = 0;
		float g_avg = 0;
		int n = 0;
		int[] grade = new int[110];
		Scanner sc = new Scanner(System.in);
		if(sc.hasNext()){
			n = sc.nextInt();
		}
		for(int i=0; i< n; i++){
			if(sc.hasNext()){
				grade[i] = sc.nextInt();
				g_avg += grade[i];
			}
		}		
		g_avg = g_avg/n;
		for(int i=0; i< n; i++){
			for(int j= i+1; j <n;j++){
				int ma = max_Array(grade[i],grade[j]);
				int mi = min_Array(grade[i],grade[j]);
				if(g_max <ma){
					g_max = ma;
				}
				if(g_min == 0){
					g_min = mi;
				}
				else if(g_min >mi ){
					g_min = mi;
				}
			}
			
		}	
		System.out.println(g_max);
		System.out.println(g_min);
		System.out.printf("%.2f",g_avg);
	
	} 
	public static int max_Array(int a,int b){
		return a>b?a:b;
	}
	public static int min_Array(int a,int b){
		return a<b?a:b;
	}

}




G:单词分析

G-2020
G-2020-2

方法

  1. 预定义字母数组
  2. TreeMap键值对存储字符数据
  3. 数值统计
  4. 寻找出现次数最多的键值

方案代码:

public class G2020 {
	public static void main(String[] args) {
		Map<Character,Integer> map = new TreeMap<Character,Integer>();
		//		初始化集合
		for(int i = 97; i< 123; i++){
			map.put((char)i, 0);
		}
		String word	= null;
		Scanner sc = new Scanner(System.in);
		if(sc.hasNext()){
			word	= sc.next();
		}
		int l = word.length();
		for(int i = 0; i< l;i++){
			char c = word.charAt(i);
			if(map.containsKey(c)){
			int temp = map.get(c);
			//这里获取到的temp是 0,需要++在前
			map.put(c, ++temp);
			}
	
		}
//寻找最大值,输出对应的字母,这里并没有对Map进行排序
		int max = 0;
		char max_c = 0;
		for(int i = 97; i< 123; i++){
			int temp = map.get((char)i);
			if( temp > max){
				max = temp;
				max_c = (char)i;
			}
		}
		System.out.println(max);
		System.out.println(max_c);
	}	
}

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值