#43119:


w122322222@gmail.com (m n j h p)

學校 : 不指定學校
編號 : 289597
來源 : [140.136.20.201]
最後登入時間 :
2024-10-27 20:06:50
a743. 10420 - List of Conquests -- UVa10420 | From: [140.136.33.249] | 發表日期 : 2024-10-17 13:43

要比整個字串 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.

}
}
 
ZeroJudge Forum