• (JAVA)[COCI2006-2007#2] ABC


    [COCI2006-2007#2] ABC

    一、题目描述

    • 三个整数分别为 A , B , C A,B,C A,B,C。这三个数字不会按照这样的顺序给你,但它们始终满足条件: A < B < C A < B < C A<B<C。为了看起来更加简洁明了,我们希望你可以按照给定的顺序重新排列它们。

    二、输入格式

    • 第一行包含三个正整数 A , B , C A,B,C A,B,C,不一定是按这个顺序。这三个数字都小于或等于 100 100 100。第二行包含三个大写字母 A A A B B B C C C(它们之间没有空格)表示所需的顺序。

    三、输出格式

    • 在一行中输出 A A A B B B C C C,用一个 (空格)隔开。

    四、输入输出样例

    在这里插入图片描述

    五、代码

    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int A = sc.nextInt();
            int B = sc.nextInt();
            int C = sc.nextInt();
            int D = 0;
            String s = sc.next();
            int[] array = {A,B,C};
            for (int i = 0; i < array.length; i++) {
                for (int j = i + 1; j < array.length; j++) {
                    if (array[i] > array[j]){
                        D = array[i];
                        array[i] = array[j];
                        array[j] = D;
                    }
                }
            }
            A = array[0];
            B = array[1];
            C = array[2];
            String result;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == 'A') {
                    System.out.print(A);
                    System.out.print(" ");
                    continue;
                }
                if (s.charAt(i) == 'B') {
                    System.out.print(B);
                    System.out.print(" ");
                    continue;
                }
                if (s.charAt(i) == 'C'){
                    System.out.print(C);
                    System.out.print(" ");
                    continue;
                }
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    六、知识点

    (1) java简单排序(数字)

    • 方法一:冒泡排序
    public class Main {
        public static void main(String[] args) {
            int[] array = {5,8,3};
            int a = 0;
            for (int i = 0; i < array.length; i++) {
                for (int j = i + 1; j < array.length; j++) {
                    if (array[i] > array[j]){
                        a = array[i];
                        array[i] = array[j];
                        array[j] = a;
                    }
                }
            }
            for (int i = 0; i < array.length; i++) {
                System.out.print(array[i] + " ");
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 方法二:快速排序法(运用Arrays类中的Arrays.sort方法()实现)
    import java.util.Arrays;
    
    public class Main {
        public static void main(String[] args) {
            int[] array = {5,8,3};
            Arrays.sort(array);
            for (int i = 0; i < array.length; i++) {
                System.out.print(array[i] + " ");
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  • 相关阅读:
    sql 注入, 报错型注入
    spark学习笔记(十)——sparkSQL核心编程-自定义函数UDF、UDAF/读取保存数据/五大数据类型
    Python环境搭建
    电容知识点
    windows11对编程有用的功能
    人机交互——对话管理
    什么是多云? 为什么我们需要多云可观测性 (Observability)?
    《机器人SLAM导航核心技术与实战》第1季:第6章_机器人底盘
    大屏小程序探索实践 | Cube 技术解读
    践行这两个方法,跳出一切情绪的制约
  • 原文地址:https://blog.csdn.net/xjl243636988/article/details/127706121