TopCoder problem "AttendanceShort" used in SRM 352 (Division II Level One)



Problem Statement

    The students at your university have lately picked up the annoying habit of missing classes. To fix this problem your board has decided to only allow students with 75% or higher attendance to sit for the exams. Given a String[] names containing the students' names and a String[] attendance containing their attendance records, return the list of students who have less than 75% attendance.



The ith student's name is given as the ith element of names and his attendance record as the ith element of attendance. The attendance record corresponding to each student is specified as a string of 'A's, 'P's and 'M's. An 'A' indicates the students was absent for a class, whereas a 'P' means he was present and a 'M' means he was absent but he submitted a doctor's note for that class. If a student was absent for a class but submitted a doctor's note then that class is not counted when calculating his attendance percentage. Return a String[] containing the names of all the students who do not meet the attendance requirements. The names in the returned String[] should be in the same relative order as names.
 

Definition

    
Class:AttendanceShort
Method:shortList
Parameters:String[], String[]
Returns:String[]
Method signature:String[] shortList(String[] names, String[] attendance)
(be sure your method is public)
    
 

Constraints

-names will contain between 0 and 50 elements, inclusive.
-attendance will contain the same number of elements as names.
-Each element of names will contain between 1 and 50 characters, inclusive.
-Each element of attendance will contain between 1 and 50 characters, inclusive.
-Each element of names will contain only letters ('A' - 'Z' and 'a' - 'z').
-Each element of attendance will contain only 'A', 'P' and 'M' characters.
-Each element of attendance will contain at least one 'A' or 'P' character.
 

Examples

0)
    
{"Justin"}
{"PAAPP"}
Returns: {"Justin" }
Justin has attended 3 of his 5 classes which gives him 3/5 * 100 = 60% attendance. Since this is lower than 75% his name should be returned.
1)
    
{"Justin","Chris"}
{"PAAPP","PPPPA"}
Returns: {"Justin" }
Chris has attended 4 out of his 5 classes and thus has 80% attendance. Justin has 60% so only Justin's name should be returned.
2)
    
{"Sunny"}
{"PPPAM"}
Returns: { }
Sunny's attendance is effectively calculated from "PPPA" as classes which have a doctor's note are ignored. This results in a 75% attendance and so his name is not included in the returned list.
3)
    
{"Mansi", "Arjun", "Nikhil", "Taneja"}
{"PPPPMPPAPP", "AAMAAPP", "PPPPAAP", "PPPAAAMPP"}
Returns: {"Arjun", "Nikhil", "Taneja" }
4)
    
{}
{}
Returns: { }
Take care of the empty case.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7777

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10709&pm=7777

Writer:

Ishan

Testers:

PabloGilberto , brett1479 , Olexiy , Andrew_Lazarev

Problem categories:

Simple Search, Iteration