-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunny String.php
47 lines (37 loc) · 916 Bytes
/
Funny String.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
<?php
/**
* @author: syed ashraf ullah
* date: 29/04/2020
* problem: https://www.hackerrank.com/challenges/funny-string/problem
*/
// Complete the funnyString function below.
function funnyString($s) {
$s = str_split($s);
$lenth = sizeof($s)-1;
for ($i=0, $j=$lenth; $i < $lenth; $i++,$j--) {
$dif1 = ord($s[$i]) - ord($s[$i+1]);
$dif2 = ord($s[$j]) - ord($s[$j-1]);
if (abs($dif1) != abs($dif2)){
return 'Not Funny';
}
}
return 'Funny';
}
/**
* Sample 1
*/
// $s = 'acxz';
// $result = funnyString($s);
// echo $result;
// return;
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%d\n", $q);
for ($q_itr = 0; $q_itr < $q; $q_itr++) {
$s = '';
fscanf($stdin, "%[^\n]", $s);
$result = funnyString($s);
fwrite($fptr, $result . "\n");
}
fclose($stdin);
fclose($fptr);