• 第十三届蓝桥杯大赛湖南中医药大学第1场选拔赛总结(java版)


    目录

    2103: ICPC

    2047: 三维迷宫

    2062: X星间谍

    2086: 奖牌榜

    2064: 两个集合

    2065: 数字盒子

    2066: 幸运数

    2067: 十六进制


    2103: ICPC


    [命题人 : admin]
    时间限制 : 1.000 sec 内存限制 : 128 MB
    题目描述
    ICPC是国际大学生程序设计竞赛(International Collegiate Programming Contest)的简称,是全球最具影响力的大学生程序设计竞赛。
    小Kimi的目标是长大之后能够参加ICPC全球总决赛(World Final),为此他在努力学习编程。
    为了表达对ICPC的热爱,他决定编写一个程序,输入一个正整数N,输出N个连续的ICPC,同时他希望所有位于奇数位置的ICPC全部用大写字母,而偶数位置的ICPC全部用小写字母,即“icpc”。你试试能不能写出来?
    输入
    单组输入。
    输入一个正整数N,N<=100。
    输出
    输出一行,包含N个连续的“ICPC”,其中奇数位置的ICPC全部用大写字母,而偶数位置的ICPC全部用小写字母。
    样例输入 Copy
    3
    样例输出 Copy
    ICPCicpcICPC
    代码:
     

    1. import java.util.Scanner;
    2. public class Main{
    3. public static void main(String[] args) {
    4. Scanner scan=new Scanner(System.in);
    5. int n=scan.nextInt();
    6. for(int i=1;i<=n;i++){
    7. if(i%2!=0){
    8. System.out.print("ICPC");
    9. }else {
    10. System.out.print("icpc");
    11. }
    12. }
    13. }
    14. }

    2047: 三维迷宫

    [命题人 : admin]

    时间限制 : 1.000 sec  内存限制 : 128 MB

    题目描述

    小米同学在MC("我的世界")游戏中用积木块搭建了一个三维迷宫。
    在三维迷宫中,X轴对应东西方向(东为正,西为负),Y轴对应南北方向(北为正,南为负),Z轴对应上下方向(上为正,下为负)。
    现在小米在游戏中所控制的人物角色的初始坐标位置是(x, y, z),每接收到一个指令字符,角色将朝对应的方向移动一个单位长度。
    在游戏中一共包含六个指令字符,“E”表示往东移动,“W”表示往西移动,“S”表示往南移动,“N”表示往北移动,“U”表示往上移动,“D”表示往下移动。
    请问在执行一组移动指令后,人物角色的最终位置是多少?请按照X、Y和Z的顺序输出。

    输入

    单组输入。
    第1行输入三个整数x、y和z,表示人物角色的初始坐标位置。其中,-1000<=x,y,z<=1000。两两之间用英文空格隔开。
    第2行输入一个由六种字符“E”、“W”、“S”、“N”、“U”和“D”组成的字符串,字符串的长度不超过1000。

    输出

    输出移动之后人物角色的最终位置,按照X、Y和Z的顺序输出,两两之间用英文空格隔开。

    样例输入 Copy

    0 0 0
    EWESNDUS

    样例输出 Copy

    1 -1 0
    1. import java.util.Scanner;
    2. public class Main{
    3. public static void main(String[] args) {
    4. Scanner scan=new Scanner(System.in);
    5. int x= scan.nextInt();
    6. int y= scan.nextInt();
    7. int z= scan.nextInt();
    8. String str=scan.next();
    9. String[] arr=str.split("");
    10. for(int i=0;i
    11. if (arr[i].equals("E")){
    12. x+=1;
    13. } else if (arr[i].equals("W")) {
    14. x-=1;
    15. }
    16. else if (arr[i].equals("S")) {
    17. y-=1;
    18. }
    19. else if (arr[i].equals("N")) {
    20. y+=1;
    21. }
    22. else if (arr[i].equals("U")) {
    23. z+=1;
    24. }
    25. else if (arr[i].equals("D")) {
    26. z-=1;
    27. }
    28. }
    29. System.out.println(x+" "+y+" "+z);
    30. }
    31. }

    2062: X星间谍

    [命题人 : admin]

    时间限制 : 1.000 sec  内存限制 : 128 MB

    题目描述

    X星最近潜入了很多来自别的星球的间谍。
    X星首领下令在X星都城门口实施实名登记制,每一个进出X星都城的人都需要登记。进城门时需要登记一下编号,出城门时需要再登记一下编号。
    X星首领获得了一个疑似间谍的人的编号清单,假定最开始时所有疑似间谍的人都在城外。现在给出N个已经登记的编号(同一个人进城门和出城门的编号相同),因为有的人会反复进出X星都城,所以有的编号会被登记多次,但可以确保每一次登记都是真实可靠的。
    请你根据这些登记的编号信息判断还有多少疑似间谍者仍然停留在X星都城内。

    输入

    单组输入。
    第1行输入一个正整数N,表示N个被登记的编号。(N<=10^4)
    第2行输入N个被登记的编号(字符串类型),两两之间用英文空格隔开,可能会有一些编号重复。

    输出

    输出疑似间谍者仍然停留在X星都城内的数量。

    样例输入 Copy

    6
    0001 0002 0001 0002 0003 0002

    样例输出 Copy

    2

    代码:

    1. import java.util.HashSet;
    2. import java.util.Scanner;
    3. import java.util.Set;
    4. public class Main {
    5. public static void main(String[] args) {
    6. Scanner scan=new Scanner(System.in);
    7. int count=0;
    8. int n= Integer.parseInt(scan.nextLine());
    9. String line= scan.nextLine();
    10. String[] arr=line.split(" ");
    11. Set set=new HashSet<>();
    12. for (int i=0;i< arr.length;i++){
    13. set.add(arr[i]);
    14. }
    15. String[] arr1=set.toArray(new String[set.size()]);
    16. int[] m=new int[arr1.length];
    17. for(int i=0;i< arr1.length;i++){
    18. for (int j=0;j
    19. if(arr1[i].equals(arr[j])){
    20. m[i]++;
    21. }
    22. }
    23. for(int i=0;i
    24. if(m[i]%2!=0){
    25. count++;
    26. }
    27. }
    28. System.out.println(count);
    29. }}

    2086: 奖牌榜

    [命题人 : admin]

    时间限制 : 1.000 sec  内存限制 : 128 MB

    题目描述

    X星学校的运动会正在激烈进行中。
    现在需要请你编写一个程序来显示所有班级的奖牌榜,显示规则如下:
    (1) 优先按照金牌数量降序排列后显示。
    (2) 如果金牌数相等则比较银牌数,银牌数多者显示在前。
    (3) 如果金牌和银牌数都相等,则比较铜牌数,铜牌数多者显示在前。
    (4) 如果金、银、铜数量均相等,则按照班级编号从小到大排列后显示。
    (5) 需要按照班级编号、金牌数、银牌数、铜牌数、奖牌总数的顺序显示每个班级的奖牌情况。
    已知X星学校的班级编号为一个四位正整数,且班级编号具有唯一性。

    输入

    单组输入。
    第1行输入一个正整数N,表示班级的总数量,N<=9000。
    接下来N行,每1行包含四个正整数,分别表示班级编号、金牌数、银牌数和铜牌数。金牌数、银牌数和铜牌数均小于100。两两之间用英文空格隔开。

    输出

    显示按照规则排序之后的奖牌榜,每一行都包含班级编号、金牌数、银牌数、铜牌数和奖牌总数,两两之间用英文空格隔开。

    样例输入 Copy

    4
    1000 4 10 5
    1001 5 11 6
    1002 4 11 4
    1003 4 10 5

    样例输出 Copy

    1001 5 11 6 22
    1002 4 11 4 19
    1000 4 10 5 19
    1003 4 10 5 19
    1. import java.util.Scanner;
    2. public class Main{
    3. public static void main(String[] args) {
    4. Scanner scan = new Scanner(System.in);
    5. int n = scan.nextInt();
    6. int[][] arr = new int[n][4];
    7. for (int i = 0; i < n; i++) {
    8. for (int j = 0; j < 4; j++) {
    9. arr[i][j] = scan.nextInt();
    10. }
    11. }
    12. Student[] stu = new Student[n];
    13. for (int i = 0; i < n; i++) {
    14. stu[i] = new Student(arr[i][0], arr[i][1], arr[i][2], arr[i][3]);
    15. }
    16. Student temp;
    17. //冒泡排序
    18. for (int i = 0; i < n - 1; i++) {
    19. for (int j = 1; j < n - i; j++) {
    20. if (stu[j - 1].getClassno() > stu[j].getClassno()) {
    21. temp = stu[j - 1];
    22. stu[j - 1] = stu[j];
    23. stu[j] = temp;
    24. }
    25. }
    26. }
    27. for (int i = 0; i < n - 1; i++) {
    28. for (int j = 1; j < n - i; j++) {
    29. if (stu[j - 1].getCopperno() < stu[j].getCopperno()) {
    30. temp = stu[j - 1];
    31. stu[j - 1] = stu[j];
    32. stu[j] = temp;
    33. }
    34. }
    35. }
    36. for (int i = 0; i < n - 1; i++) {
    37. for (int j = 1; j < n - i; j++) {
    38. if (stu[j - 1].getSilverno() < stu[j].getSilverno()) {
    39. temp = stu[j - 1];
    40. stu[j - 1] = stu[j];
    41. stu[j] = temp;
    42. }
    43. }
    44. }
    45. for (int i = 0; i < n - 1; i++) {
    46. for (int j = 1; j < n - i; j++) {
    47. if (stu[j - 1].getGoldno() < stu[j].getGoldno()) {
    48. temp = stu[j - 1];
    49. stu[j - 1] = stu[j];
    50. stu[j] = temp;
    51. }
    52. }
    53. }
    54. for (int i = 0; i < n; i++) {
    55. int sum=stu[i].getGoldno()+stu[i].getSilverno()+stu[i].getCopperno();
    56. System.out.println(stu[i].getClassno() + " " + stu[i].getGoldno()+ " " + stu[i].getSilverno()+ " " + stu[i].getCopperno()+" "+sum);
    57. }
    58. }
    59. }
    60. class Student{
    61. private int classno;
    62. private int goldno;
    63. private int silverno;
    64. private int copperno;
    65. public Student(int classno,int goldno,int silverno,int copperno){
    66. this.classno = classno;
    67. this.goldno = goldno;
    68. this.silverno = silverno;
    69. this.copperno = copperno;
    70. }
    71. public int getClassno() {
    72. return classno;
    73. }
    74. public int getGoldno() {
    75. return goldno;
    76. }
    77. public int getSilverno() {
    78. return silverno;
    79. }
    80. public int getCopperno() {
    81. return copperno;
    82. }
    83. }

    2064: 两个集合

    [命题人 : admin]

    时间限制 : 1.000 sec  内存限制 : 128 MB

    题目描述

    现在有两个分别包含M和N个整数的集合S1和S2。S1中的元素互不相同,S2中的元素也互不相同。
    给定一个整数K,然后从S1和S2中各选取一个整数,使得其和等于K。请问一共存在多少种不同的选取方案?
    从S1中选取A、从S2中选取B与从S1中选取B、从S2中选取A是两种不同的选取方案。如果一种选取方案都不存在,则输出0。

    输入

    单组输入。
    第1行输入三个整数M、N和K,其中,M和N均不超过10000。
    第2行输入M个不同的整数,对应集合S1中的M个元素。
    第3行输入N个不同的整数,对应集合S2中的N个元素。

    输出

    输出不同选取方案的数量;如果一种选取方案都不存在,则输出0。

    样例输入 Copy

    3 4 0
    -1 1 2
    -2 1 -1 0

    样例输出 Copy

    3

    代码:

    1. import java.util.Scanner;
    2. public class Main{
    3. public static void main(String[] args) {
    4. Scanner scan=new Scanner(System.in);
    5. int m= scan.nextInt();
    6. int n= scan.nextInt();
    7. int k= scan.nextInt();
    8. int[] S1=new int[m];
    9. int[] S2=new int[n];
    10. int count=0;
    11. for(int i=0;i
    12. S1[i]=scan.nextInt();
    13. }
    14. for(int i=0;i
    15. S2[i]=scan.nextInt();
    16. }
    17. for(int i=0;i
    18. for(int j=0;j
    19. if((S1[i]+S2[j])==k){
    20. count++;
    21. }
    22. }
    23. }
    24. System.out.println(count);
    25. }
    26. }

    2065: 数字盒子

    [命题人 : admin]

    时间限制 : 1.000 sec  内存限制 : 128 MB

    题目描述

    小米同学设计了一个数字盒子,只允许在该盒子的顶部对数字进行操作,操作类型包括以下三类:
    (1) Add操作:如果盒子顶部有数字,则将数字加1;如果没有数字,则该操作无效。
    (2) Push操作:将一个新的数字增加到盒子顶部,新增数字的初始值均为1(盒子可以装下所有的数字)。
    (3) Pop操作:删除数字盒子顶部的数字;如果没有数字,则该操作无效。
    请问通过N次操作之后,盒子顶部的数字是多少?如果最后盒子的顶部已经没有数字,则输出“No number.”。

    输入

    单组输入。
    第1行输入一个正整数N(N<=1000)表示操作的总数量。
    接下来N行每行包含一个操作指令,操作指令包括三类,分别是:Add、Push和Pop。

    输出

    输出通过N个操作之后盒子顶部的数字;如果最后盒子的顶部已经没有数字,则输出“No number.”。

    样例输入 Copy

    6
    Push
    Add
    Pop
    Push
    Add
    Add

    样例输出 Copy

    3

    代码:

    1. import java.util.Scanner;
    2. public class Main{
    3. public static void main(String[] args) {
    4. Scanner scan=new Scanner(System.in);
    5. int n=scan.nextInt();
    6. String[] arr=new String[n];
    7. for(int i=0;i
    8. arr[i]= scan.next();
    9. }
    10. int j=0;
    11. int[] a=new int[1002];
    12. for(int i=0;i
    13. if(arr[i].equals("Push")){
    14. j++;
    15. a[j]=1;
    16. }else if(arr[i].equals("Add")&&a[j]!=0){
    17. a[j]++;
    18. }else if(arr[i].equals("Pop")&&a[j]!=0){
    19. a[j]=0;
    20. j--;
    21. }
    22. }
    23. if(a[j]!=0){
    24. System.out.println(a[j]);
    25. }else {
    26. System.out.println("No number.");
    27. }
    28. }
    29. }

    2066: 幸运数

    [命题人 : admin]

    时间限制 : 1.000 sec  内存限制 : 128 MB

    题目描述

    小米爸爸的生日是6月17日,因此他特别喜欢“6”和“17”这两个数字,而且他觉得所有包含“6”和“17”的数字都是他的幸运数。当然“17”中的“1”和“7”必须连在一起才行。
    现在输入两个正整数M和N,1<=M

    输入

    单组输入。
    输入两个正整数M和N,满足1<=M 两个正整数之间用英文空格隔开。

    输出

    输出在M和N之间满足要求的幸运数的个数。

    样例输入 Copy

    1 20

    样例输出 Copy

    3

    代码:

    1. import java.util.Scanner;
    2. public class Main{
    3. public static void main(String[] args) {
    4. Scanner scan=new Scanner(System.in);
    5. int m= scan.nextInt();
    6. int n= scan.nextInt();
    7. int count=0;
    8. for(;m<=n;m++){
    9. String x= String.valueOf(m);
    10. if(x.contains("6")||x.contains("17")){
    11. count++;
    12. }
    13. }
    14. System.out.println(count);
    15. }
    16. }

    2067: 十六进制

    [命题人 : admin]

    时间限制 : 1.000 sec  内存限制 : 128 MB

    题目描述

    小米同学最近在学习进制转换。众所周知,在表示十六进制数时,除了0-9这九个阿拉伯数字外,还引入了“A”、“B”、“C”、“D”、“E”和“F”这六个英文字母(不区分大小写)。
    现在给你一个十进制正整数,请问在将其转换为十六进制之后,对应的十六进制表示中有多少位是字母?

    输入

    单组输入。
    输入一个十进制正整数N(N<=10^6)。

    输出

    输出将N转换成十六进制数字后所包含的字母位的数量,如果没有字母位则输出0。

    样例输入 Copy

    20

    样例输出 Copy

    0
    1. import java.util.Scanner;
    2. public class Main{
    3. public static void main(String[] args) {
    4. Scanner scan=new Scanner(System.in);
    5. int n=scan.nextInt();
    6. int count=0;
    7. while(n!=0){
    8. if(n%16>=10){
    9. count++;
    10. }
    11. n=n/16;
    12. }
    13. System.out.println(count);
    14. }
    15. }

  • 相关阅读:
    Vue基础使用
    操作系统中文件系统的实现和分配方式探析(上)
    NR/5G - PUSCH repetition次数
    umi4项目:支持适配IE浏览器
    Android 13 现已正式发布,看看有哪些更新!
    linux进程间通讯--信号量
    中断下半部之 tasklet
    MATLAB图像处理入门
    vue导入导出csv文件(插件papaparse + jschardet)
    【云原生 | 44】Docker搭建Registry私有仓库之管理访问权限
  • 原文地址:https://blog.csdn.net/m0_53653948/article/details/128090835