Created
May 28, 2020 02:12
-
-
Save zeitan/0b9bd0ee1baf51eeb09743b6e5cc859d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int countScore(String[] T, String[] R) { | |
Map<String, Boolean> groups = new HashMap<>(); | |
int countOkIndividualTests = 0; | |
int countIndividuals = 0; | |
final String OK = "OK"; | |
for (int i = 0; i < T.length; i++) { | |
String nameTest = T[i]; | |
Character lastCharacter = nameTest.charAt(nameTest.length() -1); | |
if (lastCharacter >= 'a' && lastCharacter <= 'z') { | |
String nameGroup = nameTest.substring(0, nameTest.length() - 1); | |
boolean testStatus = R[i].equals(OK); | |
boolean testGroupStatus = groups.getOrDefault(nameGroup, true); | |
groups.put(nameGroup, testGroupStatus && testStatus); | |
} | |
else { | |
if (R[i].equals(OK)) | |
++countOkIndividualTests; | |
++ countIndividuals; | |
} | |
} | |
int countGroupsOK = Collections.frequency(new ArrayList<> (groups.values()) , true); | |
double result = ((countGroupsOK + countOkIndividualTests) * 100.0 ) / (countIndividuals + groups.size()); | |
int resultInt = (int) result; | |
int decimalPartAsUnit = (int )((result-resultInt) * 10); | |
if (resultInt % 10 < decimalPartAsUnit) | |
++resultInt; | |
return resultInt; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment