Posts marked with "Hacker Cup" in tags

Facebook Hacker Cup 2013:Beautiful Strings solution in PHP

Here is the solution for FHC 2013 Beautiful Strings problem in PHP:

$ip = fopen(‘input.txt‘, "r");
$test_cases = trim(fgets($ip));
    $c=1;
    while($c!= $test_cases+1){
        $case=preg_replace(‘/[^a-z]+/’, ", strtolower(trim(fgets($ip))));
        $vals=array_count_values(str_split($case));
        arsort($vals);
        $beauty=26;
        $max_b=0;
        foreach($vals as $v){
            $max_b +=$v*$beauty;
            $beauty–;
        }
        print("Case #".$c.": ".$max_b);
        if($c < $test_cases){
            print("
");
        }
        $c++;
    }

... [READ MORE]

Follow/Subscribe

Telegram 

Mastodon  Twitter

GitHub GitLab

Subdomains

Demos  Lab

Past

This blog was once on WordPress. Now a static site. See source code on

GitLab