Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created February 11, 2011 13:50
Show Gist options
  • Select an option

  • Save emad-elsaid/822359 to your computer and use it in GitHub Desktop.

Select an option

Save emad-elsaid/822359 to your computer and use it in GitHub Desktop.
<?php
$input = trim(file_get_contents('C-large-practice.in'));
$input = explode("\n",$input);
$input = array_slice($input,1);
$alter = array(
'a'=>'2',
'b'=>'22',
'c'=>'222',
'd'=>'3',
'e'=>'33',
'f'=>'333',
'g'=>'4',
'h'=>'44',
'i'=>'444',
'j'=>'5',
'k'=>'55',
'l'=>'555',
'm'=>'6',
'n'=>'66',
'o'=>'666',
'p'=>'7',
'q'=>'77',
'r'=>'777',
's'=>'7777',
't'=>'8',
'u'=>'88',
'v'=>'888',
'w'=>'9',
'x'=>'99',
'y'=>'999',
'z'=>'9999',
' '=>'0'
);
$final = '';
foreach( $input as $k=>$line )
{
$output = '';
for( $i=0; $i<strlen($line); $i++ )
{
$char = $alter[$line[$i]];
if( $char[0]==$output[strlen($output)-1] )
$output .= ' ';
$output .= $char;
}
$l = $k+1;
$final .= "Case #{$l}: ".$output."\n";
}
file_put_contents('output.out', trim($final));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment