• 58笔试-忘记题目


    第一题

    import java.util.HashSet;
    import java.util.Scanner;
    import java.util.Set;
    
    public class Main1 {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            String str = input.nextLine();
            String[] arr = str.split(",");
            Set<String> set = new HashSet<>();
            for (int i = 0; i < arr.length; i++) {
                set.add(arr[i]);
            }
            System.out.println(set.size());
    
            input.close();
        }
    }

    第二题

    import java.util.Scanner;
    
    public class Main2 {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            int n = input.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = input.nextInt();
            }
    
            int[] left = new int[n];
            for (int i = 1; i < arr.length; i++) {
                if (arr[i] > arr[i - 1]) {
                    left[i] = left[i - 1] + 1;
                }
                if (arr[i]==arr[i-1]){
                    left[i]=left[i-1];
                }
            }
    
            int[] right = new int[n];
            for (int i = arr.length - 2; i > 0; i--) {
                if (arr[i] > arr[i + 1]) {
                    right[i] = right[i + 1] + 1;
                }
                if (arr[i] == arr[i + 1]) {
                    right[i] = right[i + 1];
                }
            }
    
            int[] result = new int[n];
            for (int i = 0; i < n; i++) {
                if (left[i] >= right[i]) {
                    result[i] = left[i];
                } else {
                    result[i] = right[i];
                }
            }
    
            int sum = n;
            for (int i = 0; i < n; i++) {
                sum += result[i];
            }
    
            System.out.println(sum);
    
    
            input.close();
        }
    }

    第三题

    import java.util.Scanner;
    
    public class Main3 {
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            int a = input.nextInt();
            int b = input.nextInt();
    
            int[][] arr = new int[a][b];
    
            int[][] result = new int[a][b];
    
            for (int i = 0; i < a; i++) {
                for (int j = 0; j < b; j++) {
                    arr[i][j] = input.nextInt();
                }
            }
            
            
            result[0][0] = arr[0][0];
            for (int i = 1; i < a; i++) {
                result[i][0] = result[i - 1][0] + arr[i][0];
            }
    
            for (int i = 1; i < b; i++) {
                result[0][i] = result[0][i - 1] + arr[0][i];
            }
    
            for (int i = 1; i < a; i++) {
                for (int j = 1; j < b; j++) {
                    result[i][j] = Math.min(result[i][j - 1], result[i - 1][j]) + arr[i][j];
                }
            }
    
            System.out.println(result[a - 1][b - 1]);
    
            input.close();
    
        }
    }
  • 相关阅读:
    Android用Application设置全局变量以及使用
    Android Spinner
    margin和padding的区别
    Java中Calendar常用方法封装
    Java中Calendar的用法以及获取当前日期的后一天
    Oracle Exists用法
    (Oracle)rownum用法详解
    Android中GestureDetector.OnGestureListener
    Java文件路径详解[转载]
    Android利用ViewFlipper实现屏幕切换动画效果
  • 原文地址:https://www.cnblogs.com/GG-Bond/p/11571393.html
Copyright © 2020-2023  润新知