-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrading.php
43 lines (32 loc) · 878 Bytes
/
grading.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
function gradingStudents($grades) {
$finalGrades = [];
foreach ($grades as $key => $grade)
{
if ($grade >= 38){
$nextMultipliedNumber = round(($grade+5/2)/5)*5;
if (($nextMultipliedNumber - $grade) < 3)
{
$finalGrades[] = $nextMultipliedNumber;
}
else{
$finalGrades[] = $grade;
}
}else{
$finalGrades[] = $grade;
}
}
return $finalGrades;
}
$fptr = fopen("OUTPUT_PATH.txt", "w");
$__fp = fopen("php://stdin", "r");
fscanf($__fp, "%d\n", $n);
$grades = array();
for ($grades_itr = 0; $grades_itr < $n; $grades_itr++) {
fscanf($__fp, "%d\n", $grades_item);
$grades[] = $grades_item;
}
$result = gradingStudents($grades);
fwrite($fptr, implode("\n", $result) . "\n");
fclose($__fp);
fclose($fptr);