Problem

The Constitution of a certain country states that the leader is the person with the name containing the greatest number of different alphabet letters. (The country uses the uppercase English alphabet from A through Z.) For example, the name GOOGLE has four different alphabet letters: E, G, L, and O. The name APAC CODE JAM has eight different letters. If the country only consists of these 2 persons, APAC CODE JAM would be the leader.

If there is a tie, the person whose name comes earliest in alphabetical order is the leader.

Given a list of names of the citizens of the country, can you determine who the leader is?

Input

The first line of the input gives the number of test cases, TT test cases follow. Each test case starts with a line with an interger N, the number of people in the country. Then N lines follow. The i-th line represents the name of the i-th person. Each name contains at most 20 characters and contains at least one alphabet letter.

Output

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the name of the leader.

Limits

1 ≤ T ≤ 100.
1 ≤ N ≤ 100.

Small dataset

Each name consists of at most 20 characters and only consists of the uppercase English letters A through Z.

Large dataset

Each name consists of at most 20 characters and only consists of the uppercase English letters A through Z and ' '(space).
All names start and end with alphabet letters.

Sample

Input 
 
Output 
 
2
3
ADAM
BOB
JOHNSON
2
A AB C
DEF
Case #1: JOHNSON
Case #2: A AB C
一开始的错误解法:
 
思路:将每个名字的字母放到一个数组中,统计不同字母的个数,每个案例中个数最多的就是Leader,没有考虑到如果遇到相同字母数量的情况。incorrrect
 
package kickstart2017;
import java.io.*;
public class CountryLeader {

public static void main(String[] args) {
        File outfile = new File("D://Code//Java//workspace//kickstart2017//src//kickstart2017//outputforsmall.txt");    //创建输出文件对象
        try {
            FileWriter out =new FileWriter(outfile);    //创建FileWriter对象
            BufferedWriter bufw = new BufferedWriter(out);  //创建BufferedWriter类对象
            FileReader fr = new FileReader("D://Code//Java//workspace//kickstart2017//src//kickstart2017//A-small-practice.in");
            BufferedReader bufr = new BufferedReader(fr);     
            String cases = null;      
            //读取第一行信息得到case的值,为字符变量
            cases = bufr.readLine();
            int numofcases = Integer.parseInt(cases);    //字符串转变成int常量
            for(int j = 1;j < numofcases+1; j++){        //对每一个案列分别进行处理
                String N = null;                
                N = bufr.readLine();
                int numofnames = Integer.parseInt(N);
                int numofcharacter[] = new int[numofnames];    //数组存放每个名字的字母个数
                String nameofarrays[] = new String[numofnames];//将所有名字放入到一个字符串数组中去
                for(int k = 0;k < numofnames; k++){   //对每个名字即每行进行处理                    
                    int ch[] = new int[26];   //数组存放26个字母的出现次数
                    String names = bufr.readLine();   //读取一行,得到名字中包含所有的字母
                    nameofarrays[k] = names;
                    for(int m = 0;m < names.length();m++){
                        char c = names.charAt(m);  //依次取出每个字母
                        int index = c-'A';         //
                        ch[index] = ch[index] + 1;// 对应字母出现则存储字母的数组加1                        
                    }
                    int numofalp = 0;             //求出每个数组中不为0的元素的个数即为不同字母的个数            
                    for(int n = 0;n < 26; n++){
                        if(ch[n]>= 1){
                           numofalp++;
                        }
                    }
                    numofcharacter[k] = numofalp;  //将每个名字包含的字母数存储到数组中
                }
                int maxzhi = 0;
                int maxzhiindex = 0;
                for(int p = 0;p < numofnames;p++ ){    //求取每个案列中的最大值和其对应的名字
                    maxzhi = numofcharacter[0];
                    if(numofcharacter[p] > maxzhi){
                        maxzhi = numofcharacter[p];
                        maxzhiindex = p;
                    }
                }
                
                System.out.println("Case #"+ j +":" +" " + nameofarrays[maxzhiindex]);
                bufw.write("Case #"+ j +":" +" " + nameofarrays[maxzhiindex]);
                bufw.newLine();
            }
                        
            bufr.close();          
            fr.close();              //将FileReader流关闭
            bufw.close();
            out.close();             // 将输出流关闭
            
        } catch (FileNotFoundException e) {
            
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
    
    
}

Kickstart Practice Round 2017---A的更多相关文章

  1. Kickstart Practice Round 2017 Google

    Problem B. Vote A and B are the only two candidates competing in a certain election. We know from po ...

  2. Google kickstart 2022 Round A题解

    Speed Typing 题意概述 给出两个字符串I和P,问能否通过删除P中若干个字符得到I?如果能的话,需要删除字符的个数是多少? 数据规模 \[1≤|I|,|P|≤10^5 \] 双指针 设置两个 ...

  3. Practice Round China New Grad Test 2014 报告

    今天有Google of Greater China Test for New Grads of 2014的练习赛,主要是为了过几天的校园招聘测试做练习用的,帮助熟悉平台,题目嘛,个人觉得除了A题外, ...

  4. Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)ABCD

    A. Arpa and a research in Mexican wave time limit per test 1 second memory limit per test 256 megaby ...

  5. Codeforces Round #432 (Div. 1, based on IndiaHacks Final Round 2017) D. Tournament Construction(dp + 构造)

    题意 一个竞赛图的度数集合是由该竞赛图中每个点的出度所构成的集合. 现给定一个 \(m\) 个元素的集合,第 \(i\) 个元素是 \(a_i\) .(此处集合已经去重) 判断其是否是一个竞赛图的度数 ...

  6. D. Arpa and a list of numbers Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)

    http://codeforces.com/contest/851/problem/D 分区间操作 #include <cstdio> #include <cstdlib> # ...

  7. 【前缀和】【枚举倍数】 Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D. Arpa and a list of numbers

    题意:给你n个数,一次操作可以选一个数delete,代价为x:或者选一个数+1,代价y.你可以进行这两种操作任意次,让你在最小的代价下,使得所有数的GCD不为1(如果全删光也视作合法). 我们从1到m ...

  8. 【推导】【暴力】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) C. Five Dimensional Points

    题意:给你五维空间内n个点,问你有多少个点不是坏点. 坏点定义:如果对于某个点A,存在点B,C,使得角BAC为锐角,那么A是坏点. 结论:如果n维空间内已经存在2*n+1个点,那么再往里面添加任意多个 ...

  9. 【推导】Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) B. Arpa and an exam about geometry

    题意:给你平面上3个不同的点A,B,C,问你能否通过找到一个旋转中心,使得平面绕该点旋转任意角度后,A到原先B的位置,B到原先C的位置. 只要A,B,C构成等腰三角形,且B为上顶点.那么其外接圆圆心即 ...

随机推荐

  1. IntelliJ IDEA常用快捷键(一)

    Ctrl+J 键常用的组合 psvm:public static void main(String[] args) { } Serr: System.err.println("") ...

  2. python第一百六十九天,第十九周作业

    FIRSTCRM 学员管理开发需求: 1.分讲师\学员\课程顾问角色, 2.学员可以属于多个班级,学员成绩按课程分别统计 3.每个班级至少包含一个或多个讲师 4.一个学员要有状态转化的过程 ,比如未报 ...

  3. Linux命令一

    软件包管理命令: sudo apt-cache search package    #搜索包 sudo apt-cache show package     #获取包的相关信息,如说明.大小.版本 s ...

  4. NLog简单使用

    一.安装 二.安装后会在根目录出现NLog.config配置文件,简单修改配置文件为写入文件记录日志: <?xml version="1.0" encoding=" ...

  5. c/c++ 图的创建(二维数组法)

    c/c++ 图的创建(二维数组法) 图的概念 图由点和线组成 知道了图中有多少个点,和哪些点之间有线,就可以把一张图描绘出来 点之间的线,分有方向和无方向 创建图 创建图,实际就是创建出节点,和节点之 ...

  6. [Hive_add_10] Hive 的 serde (序列化 & 反序列化) 操作

    0. 说明 serde 是序列化和反序列化 serialize & deserialize 是将文件中的字段映射成 Hive 中的列 1. 验证 1.1 openCSVSerde CSV 为逗 ...

  7. 【English】20190307

    appropriate for 适用[əˈpropriɪt fɔr] appropriate for many business applications:

  8. Nginx使用教程(三):Nginx配置性能优化之I/O和TCP配置

    配置Nginx I/O <br\> Sendfile 当应用程序传输文件时,内核首先缓冲数据,然后将数据发送到应用程序缓冲区. 应用程序反过来将数据发送到目的地. Sendfile方法是一 ...

  9. jq stop()和:is(":animated")用法区别

    stop(true,true): 表示停止匹配元素正在进行的动画并跳转到末状态,清空未执行完的动画队列.常用于”解决光标移入移出得过快导致的动画效果与光标动作不一致“问题! jQuery stop() ...

  10. 十大PHP程序员必备工具

    十大PHP程序员必备工具 1.Notepad++ 总结来说就是小而精,7.4版本的软件包只有2.9M,比一般的IDE小数十倍,但是Notepad++的功能确是很全面的,代码高亮,语法折叠,宏功能,内置 ...