-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCaps Lock.php
More file actions
51 lines (43 loc) · 925 Bytes
/
Caps Lock.php
File metadata and controls
51 lines (43 loc) · 925 Bytes
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
<?php
/**
* @author Sunwaurl
* PHP 7.2
*/
$str = trim(fgets(STDIN));
$arr = str_split($str);
$cond1 = 0;
$cond2 = 0;
$flag1 = $flag2 = 0;
// ABC
// aABC
// ==> Change case, Ignore otherwise
if (ctype_lower($arr[0])) {
$cond1 = true;
}
if (ctype_upper($arr[0])) {
$cond2 = true;
}
if ($cond1) {
for ($i = 1; $i < count($arr); $i++) {
if (ctype_upper($arr[$i])) {
$flag1++;
}
}
}
if ($cond2) {
// echo "Cond2";
for ($i = 0; $i < count($arr); $i++) {
if (ctype_upper($arr[$i])) {
$flag2++;
}
}
}
if (ctype_lower($arr[0]) && $flag1 == strlen($str) - 1 && strlen($str) >= 1) {
$str = strtolower($str);
echo ucwords($str) . "\n";
} else if (ctype_upper($arr[0]) && $flag2 == strlen($str)) {
$str = strtolower($str);
echo $str . "\n";
} else {
echo $str . "\n";
}