package com.heima;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ClassTest {
public static void main(String[] args) {
String s = "A,AB,CD,AC,AC,B,D,A,C,C,AB,ABCD,CD,BD,AD,CD,A,A,C,D";
System.out.println(getScore(s));
}
public static String getScore(String s ){
String regex = "[ABCD]{1,4}";
String[] std ={ "A","AB","CD","AC","B","D","A","C","D","B","A","C","D","A","AD","CD","A","A","C","D"};
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(s);
String[] s1 = new String[20];
for (int i = 0;m.find() ; i++) {
s1[i]=m.group();
}
for (int i = s1.length-1; i >=0 ; i--) {
if(i==s1.length-1&&s1[i]!=null){
break;
}
else if (s1[i]!=null){
return "您少写了"+(19-i)+"个答案";
}
}
int Score = 100;
for (int i = 0; i < s1.length; i++) {
if (!(s1[i].equals(std[i]))){
Score -=5;
}
}
return "您的分数为"+Score;
}
}
|
|