• Google test Problem A. Country Leader


    题目比较简单,就是好好熟悉一下答题系统,练练手

    package leetcode152;
    
    import java.io.*;
    import java.util.Scanner;
    
    public class GoogleTest {
    
    
    
        public static void main(String[] args) throws Exception {
    
            String filename = "A-large-practice.in";
            System.setIn(new FileInputStream(filename));
            System.setOut(new PrintStream(new FileOutputStream("A-large-practice-out.txt")));
            Scanner scanner = new Scanner(System.in);
            GoogleTest ll = new GoogleTest(scanner);
            scanner.close();
    
        }
    
        public GoogleTest(Scanner in){
    
            int testSize = Integer.valueOf(in.nextLine());
    //        System.out.println(testSize);
            for (int i = 0; i < testSize; i++){
                String tt = in.nextLine();
                int Num = Integer.valueOf(tt);
                String ans = in.nextLine();
                for (int j = 1; j < Num; j++){
                    ans = Compare(ans, in.nextLine());
                }
                System.out.println("Case #" + (i+1) + ": " +ans);
            }
        }
    
        public String Compare(String str1, String str2){
    
            boolean[] Str1 = new boolean[26];
            int num1 = 0;
            for (int i = 0; i < str1.length(); i++){
                if (str1.charAt(i) == ' '){
                    continue;
                }
                int num = str1.charAt(i) - 'A';
                if (Str1[num] == false){
                    Str1[num] = true;
                    num1++;
                }
    
            }
            boolean[] Str2 = new boolean[26];
            int num2 = 0;
            for (int i = 0; i < str2.length(); i++){
                if (str2.charAt(i) == ' '){
                    continue;
                }
                int num = str2.charAt(i) - 'A';
                if (Str2[num] == false){
                    Str2[num] = true;
                    num2++;
                }
    
            }
            String ans = str1;
            if (num1 > num2){
                 ans = str1;
            } else if (num1 < num2){
                ans = str2;
            } else {
                int i = 0;
                while ( i < str1.length() && i < str2.length()){
                    if (str1.charAt(i) > str2.charAt(i)){
                        return str2;
                    } else if (str1.charAt(i) < str2.charAt(i)){
                        return str1;
                    } else {
                        i++;
                    }
                }
            }
    //        System.out.println(str1 + " " + num1 + " " + str2 + " " + num2 + " " + ans);
            return ans;
        }
    
    }
  • 相关阅读:
    使用虚拟环境virtualenv/Virtualenvwrapper隔离多个python
    计算机硬件基本知识及Linux的常用命令
    网络电子时钟系统案例
    地铁时钟系统介绍
    北斗校时服务器装置介绍
    网络电子时钟系统成功案例
    高精度统一时钟基准特点
    IEEE1588 PTP对时系统原理及特点
    GPS轨迹发生模拟器介绍
    python urllib模块
  • 原文地址:https://www.cnblogs.com/xiaoba1203/p/6502147.html
Copyright © 2020-2023  润新知