-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintSolution.php
131 lines (113 loc) · 3.71 KB
/
printSolution.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
// PRINT OUT ORIGINAL STRINGS
function printStrings($str1, $str2){
// PRINT PROBLEM WITH ALL UPPERCASE CHARACTERS
echo('<div id="answer-problem">');
echo("<strong>String 1:</strong> $str1 <br />");
echo("<strong>String 2:</strong> $str2 <br />");
echo('<br />');
echo('</div>');
}
// PRINT OUT THE ALIGNMENT GRID TABLE
function printTable($arr_str1, $arr_str2, $score, $points) {
echo('<table border="1px" table-layout="fixed">');
// PRINT HEADER FIRST ROW, WHICH IS THE SECOND STRING INPUT
echo('<tr>');
echo('<td></td><td></td>');
for ($i=0;$i<count($arr_str2);$i++){
echo('<td><strong>'.$arr_str2[$i].'</strong></td>');
}
echo('</tr>');
for ($r=0;$r<count($score);$r++){
echo('<tr valign="bottom" height="24px">');
// PRINT FIRST CELL OF EACH ROW, WHICH IS FIRST STRING INPUT
if ($r > 0)
echo('<td><strong>'.$arr_str1[$r-1].'</strong></td>');
else echo("<td></td>");
// PRINT ALIGNMENT GRID
for ($c=0;$c<count($score[0]);$c++){
if (in_array(array($r,$c),$points))
echo('<td class="pathVertex"><div><strong>'.$score[$r][$c].'</strong></div></td>');
else echo('<td>'.$score[$r][$c].'</td>');
}
echo('</tr>');
}
echo('</table>');
}
// PRINT OUT THE ALIGNMENT GRID TABLE WITH DIRECTION
function printTable2($arr_str1, $arr_str2, $score, $points, $direction) {
echo('<table border=1px table-layout=fixed>');
// PRINT HEADER FIRST ROW, WHICH IS THE SECOND STRING INPUT
echo('<tr class="tableStrHorizon">');
echo('<td class="tableStrVertical"></td><td></td>');
for ($i=0;$i<count($arr_str2);$i++){
echo('<td class="tableStr">'.$arr_str2[$i].'</td>');
}
echo('</tr>');
for ($r=0;$r<count($score);$r++){
echo('<tr>');
// PRINT FIRST CELL OF EACH ROW, WHICH IS FIRST STRING INPUT
if ($r > 0)
echo('<td class="tableStr">'.$arr_str1[$r-1].'</td>');
else echo("<td></td>");
// PRINT ALIGNMENT GRID
for ($c=0;$c<count($score[0]);$c++){
$class_direction = '';
switch ($direction[$r][$c]){
case 'u':
$class_direction = 'pathUp';
break;
case 'l':
$class_direction = 'pathLeft';
break;
case 'd':
$class_direction = 'pathDia';
break;
}
if (in_array(array($r,$c),$points))
echo('<td class="' . $class_direction . ' pathFinal"><div class="score scoreFinal">'.$score[$r][$c].'</div></td>');
else echo('<td class="' . $class_direction . '"><div class="score">'.$score[$r][$c].'</div></td>');
}
echo('</tr>');
}
echo('</table>');
}
// PRINT ALIGNED STRINGS
function printAlignment($arr_str1, $arr_str2, $path){
// INITIALIZE ALIGNED STRING AND INDEX VARIABLES
$output1 = '';
$output2 = '';
$index1 = count($arr_str1)-1;
$index2 = count($arr_str2)-1;
// PROCESS ALIGNED STRINGS IN BACKWARD ORDER
for ($i=0;$i<count($path);$i++){
switch ($path[$i]){
case 'd':
$output1 .= $arr_str1[$index1];
$output2 .= $arr_str2[$index2];
$index1--;
$index2--;
break;
case 'l':
$output1 .= '_';
$output2 .= $arr_str2[$index2];
$index2--;
break;
case 'u':
$output1 .= $arr_str1[$index1];
$output2 .= '_';
$index1--;
break;
}
}
// REVERSE STRING IN NORNAL ORDER
$output1 = strrev($output1);
$output2 = strrev($output2);
// PRINT RESULT OUT TO CLIENT
echo('<div class="alignment-answer">');
echo('<strong>ALIGNMENT:</strong><br />');
echo("$output1 <br />");
echo("$output2 <br /><br />");
echo('</div>');
}
?>