题目链接:宇宙总统
java代码:
import java.util.Arrays;
import java.util.Scanner;
class Candidate implements Comparable<Candidate>{
int id;
String votes;
public Candidate(int id, String votes) {
super();
this.id = id;
this.votes = votes;
}
public int compareTo(Candidate newCandidate) {
if(this.votes.length()!=newCandidate.votes.length())
return Integer.compare(newCandidate.votes.length(), this.votes.length());
else
return newCandidate.votes.compareTo(this.votes);
}
}
public class Main {
public static void main(String[] args) {
int n;
Scanner in = new Scanner(System.in);
n = in.nextInt();
Candidate arr[] = new Candidate[n];
for(int i=0;i<n;++i)
arr[i] = new Candidate(i+1,in.next());
Arrays.sort(arr);
System.out.println(arr[0].id);
System.out.println(arr[0].votes);
}
}