要比整個字串 java
import java.util.*;//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
class all implements Comparable<all>{
String country;
int count;
all(String input,int count){
this.country=input;
this.count=count;
}
public int compareTo(all other){
return this.country.compareTo(other.country);
}
}
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String input;
int count;
count=sc.nextInt();
ArrayList<all>all_in=new ArrayList<>();
sc.nextLine();
for(int i=0;i<count;i++){
input=sc.nextLine();
String country2=input.substring(0,input.indexOf(" "));
int k=0;
for(int y=0;y<all_in.size();y++){
if(all_in.get(y).country.equals(country2)){
all_in.get(y).count+=1;
k=1;
break;
}
}
if(k==0){
all_in.add(new all(country2,1));
}
}
Collections.sort(all_in);
for(int i=0;i<all_in.size();i++){
System.out.println(all_in.get(i).country+" "+all_in.get(i).count);
}
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
}
}