Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // You are given an array of strings, each of three characters separated by space
- //– the strengths of a card. Possible inputs for each one are from 2..9 or T, J, Q, K, A. If
- //some triple is invalid the program must output it and the following text : “Invalid cards
- //given!”. Elsewhere the program must output the triple of cards and whether it is in ascending
- //order (2..9,T,J,Q,K,A).
- <?php
- $a = ["3 4 2", "J 2 6", "1 T K", "P J K", "2 9 J",];
- $strength = ["2", "3", "4", "5", "6", "7", "8", "9","T","J","Q","K","A",]; // всички карти
- foreach ($a as $v) { // за всеки елемент от 3 символа
- echo $v.PHP_EOL; // отпечатвам 3-те карти
- $k = explode(" ", $v); // правя масив от 3 елемента - всеки е карта
- for ($i = 0; $i < count($v); $i++) { //обхождам всяка карта
- if (!in_array($k[$i], $strength)) { // Ако картата НЕ е в масива на всички карти
- $r = "Invalid Cards"; // запазвам резултата в променлива
- }else{
- if ($k[$i] === "T") $k[$i] = "10"; // присвоявам числова стойност
- if ($k[$i] === "J") $k[$i] = "11";
- if ($k[$i] === "Q") $k[$i] = "12";
- if ($k[$i] === "K") $k[$i] = "13";
- if ($k[$i] === "A") $k[$i] = "14";
- if($k[0]<$k[1] && $k[1]<$k[2]) { //сравням трите карти
- $r = "Ascending";
- }else {
- $r = "Not Ascending";
- }
- }
- }
- echo $r.PHP_EOL; // отпечатвам резултата
- echo PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement