I didn't see anyone mention it here (maybe I couldn't), but there is a
function in perl called grep, which allows you to match a regular
expression for each element of the array. It returns the matching
elements of the array in array context, and the number of matches in
scalar context. So putting all dictionary words into an array, then
doing grep with the pattern (of course [] instead of () ) directly
gives you the solution if you evaluate as a scalar.

 I think it replaces the foreach loop in Amol's code. Also a tip:
instead of substitution

$CurrentLine =~ s/\()/\[]/g;
$CurrentLine =~ s/\)/\]/g;

you can do translation

$CurrentLine =~ tr/()/[]/g;

On Sep 4, 10:53 am, Amol Manoj Bhave <[email protected]> wrote:
> Hey Ketan!
>  I solved it usingperland is very much fast and got me qualified.
> YEAH:
>
> open(INFILE, '<A-large.in');
> open(OUTFILE, '>A-large.out');
> $FirstLine = <INFILE>;
> @LineF = split(/\s/, $FirstLine);
> $Noofwords = @LineF[1];
> $TestCases = @LineF[2];
> @Words = ();
> for($i = 0; $i<$Noofwords;$i++)
> {
>  $str = <INFILE>;
>  push(@Words, $str);
>
> }
>
> for($CurTestCase = 1; $CurTestCase <= $TestCases; $CurTestCase++)
> {
> $CurrentLine = <INFILE>;
> $CurrentLine =~ s/\(/\[/g;
> $CurrentLine =~ s/\)/\]/g;
> $CurrentLine =~ s/^\s+|\s+$//g ;
> $noofoc = 0;
> foreach $word (@Words)
> {
>  while($word =~ /$CurrentLine/g)
>  {
>   $noofoc++;
>  }}
>
> $strtoprint = "Case #" . $CurTestCase . ": " . $noofoc . "\n";
> print $strtoprint;
> print OUTFILE $strtoprint;
>
> }
>
> On Sep 4, 1:50 pm, KeJo <[email protected]> wrote:
>
> > Hi,
>
> > anyone solved all problems correctly usingperl?
>
> > I did it, but I feel there could be better ways to do it inperl.
> > Please let me know so that I can compare.
>
> > Regards,
> > KeJo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-codejam" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-code?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to