zoukankan      html  css  js  c++  java
  • 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;
        }
    
    }
  • 相关阅读:
    第一个Django demo
    内建函数
    Git积累
    区间dp
    【Spring】Spring AOP详解(转载)
    【git】git 常用命令(含删除文件)
    【idea】idea如何在maven工程中引入jar包
    【Java】Scanner类nextInt后使用nextLine无法读取输入
    【Java_Eclipse】Eclipse插件如何卸载?
    【MySQL】MySQL5.7等以上版本在Windows上的配置
  • 原文地址:https://www.cnblogs.com/xiaoba1203/p/6502147.html
Copyright © 2011-2022 走看看