Skip to content

Instantly share code, notes, and snippets.

@zeitan
Created May 28, 2020 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeitan/0b9bd0ee1baf51eeb09743b6e5cc859d to your computer and use it in GitHub Desktop.
Save zeitan/0b9bd0ee1baf51eeb09743b6e5cc859d to your computer and use it in GitHub Desktop.
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