pyTorch Realization Relationship Exclusion

2022-12-20   ES  

Enter the following data from the keyboard: “Tom: 89 | Jerry: 90 | Tony: 95”. And sort the results from high to low.

import java.util.Scanner;
import java.util.Comparator;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
class Person{

String name;
int score;
}
class PersonComparator implements Comparator<Person>{

public int compare(Person per1,Person per2){

if(per1.equals(per2)){

return 0;
}else if(per1.score<per2.score){

return 1;
}else{

return -1;
}
}
}
public class Numdemo{

public static void main(String[] args){

System.out.println (“Please enter the content (Name: Score | Name: Score | Name: Score):););););
Scanner scan=new Scanner(System.in);
String str=scan.next();
String[] str1=str.split(“\\|”);
List<Person> list=new ArrayList<Person>();
system.out.print (“New Sorting as:”);
for(int i=0;i<str1.length;i++){

String[] str2=str1[i].split(“\\:”);
Person per=new Person();
per.name=str2[0];
per.score=Integer.parseInt(str2[1]);
list.add(per);
}
Collections.sort(list,new PersonComparator());
for(int j=0;j<list.size();j++){

Person per=list.get(j);
System.out.print(per.name+” “+per.score+” “);
}
}
}

source

Related Posts

Use SAS to implement Hadoop Map/Reduce program-wordCount

Linux C ++ Multi -thread programming foundation -condition variables and semaphores

1 1

qmuitopbar usage in qmuiandroid

pyTorch Realization Relationship Exclusion

Random Posts

Volley framework get post request

Android listView shows complex pages

Cooking and Session

OPENCV mouse control window size (1.0VISON)

16.python-Basic recognition of crawlers, the application of Python variables and string