当前位置: 首页 > news >正文

第二届全国高校计算机技能竞赛——Java赛道

第二届全国高校计算机技能竞赛——Java赛道

小赛跳高

在这里插入图片描述

签到题

import java.util.*;
public class Main{public static void main(String []args) {Scanner sc = new Scanner(System.in);double n = sc.nextDouble();for(int i = 0; i < 4; i++) {n = n * 0.9;}System.out.printf("%.2f", n);}
}

找数

在这里插入图片描述

签到题

import java.util.Scanner;
public  class Main{public static void main(String []args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();for(int i = 1; i <= n; i++) {if((i % 3 == 1) && (i % 5 == 1) && (i % 7 == 1)) {System.out.print(i + " ");}}}
}

打分

在这里插入图片描述

签到题
注意cnt等于0的情况
最大值取-0x3f3f3f3f
最小值取0x3f3f3f3f
注意当cnt = 0时,说明无人打出大于0的分数。
此时选手的分数为0分,注意保留2位小数

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();int maxsco = -0x3f3f3f3f;int minsco= 0x3f3f3f3f;int sum = 0;int cnt = 0;while (n-->0) {int sco = sc.nextInt();if (sco > 100 || sco < 1) {continue;}sum += sco;cnt++;if (sco > maxsco) {maxsco = sco;}if (sco < minsco) {minsco = sco;}}if(cnt>0) {System.out.printf("%.2f",(double) (sum - maxsco - minsco) / (cnt - 2));}else {System.out.println(0.00);} }
}

找子串

在这里插入图片描述

不断截取子串,判断后,找出最大串和最小串

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);String str1 = sc.nextLine();String minstr = str1;String maxstr = "";for (int i = 0; i < str1.length(); i++) {for (int j = i + 1; j <= str1.length(); j++) {String substr = str1.substring(i, j);if (substr.compareTo(minstr) < 0) {minstr = substr;}if (substr.compareTo(maxstr) > 0) {maxstr = substr;}}}System.out.println(minstr);System.out.println(maxstr);}
}

矩阵距离

在这里插入图片描述
在这里插入图片描述

宽搜bfs 队列存点对,往上下左右四个方向搜索
注意初始化所有距离数组dis[][]为-1

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;class Main {static final int[][] dt = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int n = scanner.nextInt();int m = scanner.nextInt();scanner.nextLine(); // 读取换行符char[][] g = new char[n][m];for (int i = 0; i < n; i++) {String line = scanner.nextLine();for (int j = 0; j < m; j++) {g[i][j] = line.charAt(j);}}bfs(g, n, m);}static void bfs(char[][] g, int n, int m) {int[][] dis = new int[n][m];Queue<int[]> q = new LinkedList<>();for(int i = 0; i < n;i++) {for(int j = 0; j < m;j++) {dis[i][j] = -1;}}for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {if (g[i][j] == '1') {dis[i][j] = 0;q.offer(new int[]{i, j});}}}while (!q.isEmpty()) {int[] t = q.poll();int x = t[0];int y = t[1];for (int i = 0; i < 4; i++) {int dx = x + dt[i][0];int dy = y + dt[i][1];if (dx >= 0 && dx < n && dy >= 0 && dy < m && dis[dx][dy] == -1) {dis[dx][dy] = dis[x][y] + 1;q.offer(new int[]{dx, dy});}}}for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {System.out.print(dis[i][j] + " ");}System.out.println();}}
}

总结

难度中下,签到题3道,medium2道。
总体难度没去年难,考查基础思维。
注意代码实现细节和边界情况

http://www.lryc.cn/news/175942.html

相关文章:

  • 使用Webpack设置TS引用模块,解决Module not found: Error: Can‘t resolve ‘./m1‘ in ...问题
  • 北斗GPS网络时钟系统(子母钟系统)助力智慧教室建设
  • 蓝牙芯片香薰机智能化方案
  • 9.23 校招 实习 内推 面经
  • ARM 和 AMD 架构的区别
  • Logstash、sharding-proxy组件高级配置
  • 【Elasticsearch】简单搜索(三)
  • 【PMP/软考】软件需求的三个主要层次:业务需求、用户需求和功能需求解释及实例解析
  • Linux基础知识 总结
  • 网上申请流量卡要不要身份证?填写的信息安全吗?
  • 关于计算机缺失vcruntime140.dll文件的解决方法分享
  • 华为乾坤区县教育安全云服务解决方案(2)
  • PL/SQL异常抓取
  • Java 18的未来:新特性和编程实践
  • 2024快手校招面试真题汇总及其解答(三)
  • 【QandA C++】内存泄漏、进程地址空间、堆和栈、内存对齐、大小端和判断、虚拟内存等重点知识汇总
  • 怒刷LeetCode的第12天(Java版)
  • RabbitMQ实现秒杀场景示例
  • 如何提升网站排名优化(百度SEO优化,轻松提升排名)
  • CountDownLatch 和 CyclicBarrier 用法以及区别
  • 9.9喝遍“茶、奶、果、酒”,茶饮价格战是因为“无活可整”?
  • echarts 学习网址
  • android源码编译
  • 盘点双电机驱动技术
  • ubuntu下用pycharm专业版连接AI服务器及其docker环境
  • IntentFilter笔记
  • 【二叉树】——链式结构(快速掌握递归与刷题技巧)
  • 项目管理—项目普遍存在的问题
  • Ubuntu Seata开机自启动服务
  • 腾讯mini项目-【指标监控服务重构】2023-08-26