展开全部
看不懂你这个e5a48de588b63231313335323631343130323136353331333335326134输出顺序
如果按“对muscle pain temperature flu 列排序 “
输出应该muscle pain为yes的都在前面。。import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
static public enum ETemp{
NORMAL("normal",0),HIGH("high",1),VERY_HIGH("very_high",2);
final public String text;
final public int v;
ETemp(String t,int v){ text=t;this.v=v;}
public String toString(){return text;}
}
static public class Patient{
public int id;
public boolean headache, muscle_pain,flu;
public ETemp temperature;
public String toString(){
return "e"+id+"\t"+(headache?"yes":"no")+"\t"+
(muscle_pain?"yes":"no")+"\t"+
temperature+"\t"+(flu?"yes":"no");
}
}
public static void main(String[] args) throws NumberFormatException, IOException {
Pattern pn=Pattern.compile(
"e(\\d+)\\s{2,}(yes|no)\\s{2,}(yes|no)\\s{2,}(normal|very high|high)\\s{2,}(yes|no)");
Files.lines(new File("data.txt").toPath()).map((line)->{
Matcher m=pn.matcher(line);
Patient p=null;
if(m.find()){
p=new Patient();
p.id=Integer.parseUnsignedInt(m.group(1));
p.headache=m.group(2).equals("yes");
p.muscle_pain=m.group(3).equals("yes");
switch(m.group(4)){
case "normal":default:p.temperature=ETemp.NORMAL;break;
case "high":p.temperature=ETemp.HIGH;break;
case "very high":p.temperature=ETemp.VERY_HIGH;break;
}
p.flu=m.group(5).equals("yes");
}
return p;
}).filter((p)->p!=null).sorted((a,b)->{
int mr=(b.muscle_pain?1:0)-(a.muscle_pain?1:0),
fr=(b.flu?1:0)-(a.flu?1:0),
tr=a.temperature.v-b.temperature.v;
return mr!=0?mr: (tr!=0?tr:fr);
}).forEach((o)->System.out.println(o));
}
}e9yesyesnormalyes
e1yesyesnormalno
e4noyesnormalno
e8noyesnormalno
e2yesyeshighyes
e3yesyesvery_highyes
e6noyesvery_highyes
e7yesnohighyes
e10nonohighyes
e5nonohighno
java 8的代码,需要java 8运行。按musclepain > temperature>flu的顺序。。。
看了半天看不懂你样例输出中到底是什么顺序,你所给的样例输出不符合任何顺序,需要解释再说。