Bugün Rəşadın tweetini gördüyüm zaman Facebook Hacker Cupın başladığından xəbərim oldu.
Birinci sualı aşağıda yazdığım kimi həll elədim. Sırf output format düzgün deyildi deyə qəbul edilmədi. Düzgün format necədir bilən var? :)
<?php
// input
$input = "5\nABbCcc\n Good luck in the Facebook Hacker Cup this year!\nIgnore punctuation, please :)\nSometimes test cases are hard to make up.\nSo I just go consult Professor Dalves";
// split input into lines
$lines = explode("\n", $input);
$number_of_lines = $lines[0];
for($i = 1; $i <= $number_of_lines; $i++)
{
// lowercase all
$string = strtolower($lines[$i]);
// ignore punctuations and space
$string = preg_replace('/[^a-z]/', '', $string);
// letter frequency
$string_letters = str_split($string);
$letter_frequency = (array_count_values($string_letters));
// sort by frequency descending
arsort($letter_frequency);
$k = 0;
foreach ($letter_frequency as $letter => $frequency)
{
$score[$i] += (26 - $k) * $frequency;
$k++;
}
}
// output
for($i = 1; $i <= $number_of_lines; $i++)
{
echo "Case #".$i.": ".$score[$i]."<br />\n";
}
Sualın keçidi: https://www.facebook.com/hackercup/problems.php?pid=475986555798659&round=185564241586420
